Get Base Templates

Get Base Templates

Base Template

  • A data template that contributes fields and sections, or settings to another data template

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Items.Item
  • Sitecore.Data.Items.TemplateItem
  • Sitecore.TemplateIDs

Base Templates C# Web Control Code

Sitecore.Data.Items.Item item = Sitecore.Context.Item;
if (item == null) return;

Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Data.Items.TemplateItem standard = db.Templates[Sitecore.TemplateIDs.StandardTemplate];
if (standard == null) return;

Sitecore.Data.Items.TemplateItem[] baseTemplates = standard.BaseTemplates;
if (baseTemplates == null) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
//using : for colon and   for space
output.Write("{0}: {1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

foreach (Sitecore.Data.Items.TemplateItem baseTemplate in baseTemplates)
{
    output.Write("{0}", "<b>" + baseTemplate.Name + "</b><br/>");
}

output.RenderEndTag(); //Div

Base Templates C# Web Control Output

Advanced
Appearance
Help
Layout
Lifetime
Insert Options
Publishing
Security
Statistics
Tasks
Validators
Workflow

Sources