Inherited Templates

Inherited Templates

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Data.Items.Item
  • Sitecore.Data.Items.TemplateItem
  • Sitecore.MainUtil

Inherited Templates C# Web Control Code

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

Sitecore.Data.Items.TemplateItem template = item.Template; 
if (template == null) return; 

Sitecore.Data.Items.TemplateItem[] templates = template.BaseTemplates; 
if (templates == 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(); //Div 

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size: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 

output.Write("{0}&#58;&#160;{1}", "Base Template", "<b>" + template.DisplayName + "</b><br/>"); 
ListTemplates(templates,output); 

output.RenderEndTag(); //Div 


private static void ListTemplates(Sitecore.Data.Items.TemplateItem[] templates, System.Web.UI.HtmlTextWriter output) 

if (templates != null) 

foreach (Sitecore.Data.Items.TemplateItem baseTemplate in templates) 

if (baseTemplate.Name.Equals("Standard template")) 

return; 

else 

output.Write("Inherits From: <b>" + baseTemplate.DisplayName + "</b><br/>"); 
Sitecore.Data.Items.TemplateItem[] baseTemplates = baseTemplate.BaseTemplates; 
ListTemplates(baseTemplates,output); 



}

Inherited Templates C# Web Control Output

Base Template: TIC-CodeSnippet
Inherits From: TIC-SnipTypePage
Inherits From: TIC-InfoTypePage
Inherits From: TIC-WebPage

Notes

  • This code displays inherited templates up to but not including the "Standard template"