Render Icons

Render Icons

Axes Property

  • Use Axes property for relative queries
  • Use Database.GetItem() method for absolute queries
  • Axes property is more efficient than absolute queries when retrieving item arrays

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Data.Items.Item
  • Sitecore.Data.Managers.ThemeManager

Render Icons C# Web Control Code

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

Sitecore.Data.Items.Item[] ancestors = item.Axes.SelectItems("ancestor::*");
if (ancestors == 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.Item ancestor in ancestors)
{
string icon = Sitecore.Data.Managers.ThemeManager.GetIconImage(ancestor, 24, 24, string.Empty, string.Empty);
output.Write("{0}", "<b>" + icon + "</b>&nbsp;");
}
   
output.RenderEndTag(); //Div


C# Web Control Real-time Output

Item: Render Icons

       

Sources