Get Renderings

Get Renderings

Renderings

  • A general term that can refer to Web control renderings, XSL renderings, URL renderings, method renderings, Web part renderings, and some uses of sublayouts


Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Fields.LayoutField
  • Sitecore.Data.Items.DeviceItem
  • Sitecore.Data.Items.Item
  • Sitecore.Layouts.RenderingReference


Renderings C# Web Control Code

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

Sitecore.Data.Fields.LayoutField layoutField = item.Fields["__renderings"];
if (layoutField == null) return;

Sitecore.Data.Items.DeviceItem[] devices = Sitecore.Context.Database.Resources.Devices.GetAll();
if (devices == 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(); // 

foreach (Sitecore.Data.Items.DeviceItem device in devices)
{
    output.Write("<br/><br/>");
    output.Write("{0}&#58;&#160;{1}", "Device Display Name", "<b>" + device.DisplayName + "</b><br/>");
    output.Write("<hr />");

    Sitecore.Layouts.RenderingReference[] renderings = layoutField.GetReferences(device);
    if (renderings != null)
    {
        int i = 0;
        foreach (Sitecore.Layouts.RenderingReference rendering in renderings)
        {
i++;
output.Write("{0}&#58;&#160;{1}", "Display Name", "<b>" + rendering.RenderingItem.DisplayName + "</b><br/>");
output.Write("{0}&#63;&#160;{1}", "Is Cacheable", "<b>" + rendering.RenderingItem.Caching.Cacheable.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Icon", "<b>" + rendering.RenderingItem.Icon + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "GUID", "<b>" + rendering.RenderingItem.ID.Guid.ToString() + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Name", "<b>" + rendering.RenderingItem.Name + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Placeholder", "<b>" + rendering.RenderingItem.Placeholder + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Tag Name", "<b>" + rendering.RenderingItem.TagName + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Tag Prefix", "<b>" + rendering.RenderingItem.TagPrefix + "</b><br/>");
if (i < renderings.Length)
    output.Write("<hr />");
        }
    }
}
output.RenderEndTag(); //Div



Renderings C# Web Control Output

Device Display Name: Default

 

 

 

Display Name: SLHeader
Is Cacheable? False
Icon: Software/16x16/element_selection.png
GUID: 2c457217-a251-439f-93f7-2a9e9d699402
Name: SLHeader
Placeholder: content
Tag Name: Sublayout
Tag Prefix: sc

 

 

 

Display Name: ShareThis
Is Cacheable? False
Icon: Software/16x16/element.png
GUID: f70bdbdd-6c36-4d99-867d-0b39c2272878
Name: ShareThis
Placeholder: HeadLowerRt
Tag Name: XslFile
Tag Prefix: sc

 

 

 

 Display Name: SLLeftContentRight
Is Cacheable? False
Icon: Software/16x16/element_selection.png
GUID: bec05755-c4a5-496a-93ea-3c6a9e798108
Name: SLLeftContentRight
Placeholder: content
Tag Name: Sublayout
Tag Prefix: sc

 

 

 

Display Name: SideMenuSimple
Is Cacheable? True
Icon: Software/16x16/element.png
GUID: 92781ac5-bf07-4b3c-9d76-c436e6abcde5
Name: SideMenuSimple
Placeholder: 
Tag Name: XslFile
Tag Prefix: sc

 

 

 

Display Name: SiteMapsLink
Is Cacheable? False
Icon: Software/16x16/element.png
GUID: 449f6899-8b93-4fe3-b669-2cf984e0ef67
Name: SiteMapsLink
Placeholder: 
Tag Name: XslFile
Tag Prefix: sc

 

 

 

Display Name: SingleSnippet
Is Cacheable? False
Icon: Software/16x16/element.png
GUID: 0f7c1732-6392-4a70-9295-94481bb89e9e
Name: SingleSnippet
Placeholder: 
Tag Name: XslFile
Tag Prefix: sc

 

 

 

Display Name: Load Demos
Is Cacheable? False
Icon: Control/32x32/multi_controls_h.png 
GUID: e30d0753-805b-487f-95da-d5898477f6ff
Name: Load Demos
Placeholder: 
Tag Name: LoadDemos
Tag Prefix: tic

 

 

 

Display Name: EngagementMenu
Is Cacheable? False
Icon: Software/16x16/element.png
GUID: 4230e784-e2f7-429a-82ac-a2836a887061
Name: EngagementMenu
Placeholder: 
Tag Name: XslFile
Tag Prefix: sc

 

 

 

Display Name: DetailsMenu
Is Cacheable? False
Icon: Software/16x16/element.png
GUID: f07a0f34-a6f3-4f18-99e5-70fd41a4e83b
Name: DetailsMenu
Placeholder: 
Tag Name: XslFile
Tag Prefix: sc


 

 

Display Name: Show Related Items
Is Cacheable? False
Icon: Control/32x32/multi_controls_h.png 
GUID: 5cb7c088-47d3-4e0b-a64e-58edf851db8f
Name: Show Related Items
Placeholder: 
Tag Name: ShowRelatedItems
Tag Prefix: tic

 

 

 

Display Name: BottomFooter
Is Cacheable? False
Icon: Software/16x16/element_selection.png
GUID: 15ca9ffe-6a29-416c-9ff0-8734333d8a94
Name: BottomFooter
Placeholder: content
Tag Name: Sublayout
Tag Prefix: sc


Device Display Name: Print

 

 

 

Display Name: Content2Rows
Is Cacheable? False
Icon: Software/16x16/element_selection.png
GUID: fe32b0c3-b9d1-4e64-bab6-9d757715180b
Name: Content2Rows
Placeholder: content
Tag Name: Sublayout
Tag Prefix: sc

 

 

 

Display Name: TitleSubtitleOnly
Is Cacheable? True
Icon: Software/16x16/element.png
GUID: b8172038-76a3-4424-b737-03a14d4f15f4
Name: TitleSubtitleOnly
Placeholder: 
Tag Name: XslFile
Tag Prefix: sc

 

 

 

Display Name: SingleSnippet
Is Cacheable? False
Icon: Software/16x16/element.png
GUID: 0f7c1732-6392-4a70-9295-94481bb89e9e
Name: SingleSnippet
Placeholder: 
Tag Name: XslFile
Tag Prefix: sc


Device Display Name: Feed

 

 

 

Display Name: FeedRenderer
Is Cacheable? False
Icon: Control/16x16/edit.png
GUID: 86f838f5-7e87-45bb-876f-c021324ac8b0
Name: FeedRenderer
Placeholder: 
Tag Name: FeedRenderer
Tag Prefix: sc

Sources