Page Renderings

Page Renderings

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Items.DeviceItem
  • Sitecore.Data.Items.Item
  • Sitecore.Layouts.RenderingReference
  • Sitecore.StringUtil

Page Renderings C# Web Control Code

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

Sitecore.Data.Items.DeviceItem device = Sitecore.Context.Device;
Sitecore.Layouts.RenderingReference[] renderings = item.Visualization.GetRenderings(device, true);
if (renderings == 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);
string itemName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using : for colon and   for space
output.Write("{0}: {1}", "Item", itemName);
output.RenderEndTag(); //P

int iRendering = 0, iRenderingCount = renderings.GetUpperBound(0);

foreach (Sitecore.Layouts.RenderingReference rendering in renderings)
{
    output.Write("{0}&#58;&#160;{1}", "Rendering Item Name", "<b>" + rendering.RenderingItem.DisplayName + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Rendering Item DataSource", "<b>" + rendering.RenderingItem.DataSource + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Rendering ID", "<b>" + rendering.RenderingID + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Rendering Placeholder", "<b>" + rendering.Placeholder + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Caching VaryByData", "<b>" + rendering.RenderingItem.Caching.VaryByData.ToString() + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Caching VaryByDevice", "<b>" + rendering.RenderingItem.Caching.VaryByDevice.ToString() + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Caching VaryByLogin", "<b>" + rendering.RenderingItem.Caching.VaryByLogin.ToString() + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Caching VaryByParm", "<b>" + rendering.RenderingItem.Caching.VaryByParm.ToString() + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Caching VaryByQueryString", "<b>" + rendering.RenderingItem.Caching.VaryByQueryString.ToString() + "</b><br/>");
    output.Write("{0}&#58;&#160;{1}", "Caching VaryByUser", "<b>" + rendering.RenderingItem.Caching.VaryByUser.ToString() + "</b>");
    if (iRendering < iRenderingCount)
        output.Write("<hr />");
    iRendering++;
}

output.RenderEndTag(); //Div


Page Renderings C# Web Control Output

 

Rendering Item Name: SLHeader
Rendering Item DataSource: 
Rendering ID: {2C457217-A251-439F-93F7-2A9E9D699402}
Rendering Placeholder: header
Caching VaryByData: False
Caching VaryByDevice: False
Caching VaryByLogin: False
Caching VaryByParm: False
Caching VaryByQueryString: False
Caching VaryByUser: False


 

 

Rendering Item Name: ShareThis
Rendering Item DataSource: 
Rendering ID: {F70BDBDD-6C36-4D99-867D-0B39C2272878}
Rendering Placeholder: HeadLowerRt
Caching VaryByData: False
Caching VaryByDevice: False
Caching VaryByLogin: False
Caching VaryByParm: False
Caching VaryByQueryString: False
Caching VaryByUser: False


 

 

Rendering Item Name: SLLeftContentRight
Rendering Item DataSource: 
Rendering ID: {BEC05755-C4A5-496A-93EA-3C6A9E798108}
Rendering Placeholder: mainbody
Caching VaryByData: False
Caching VaryByDevice: False
Caching VaryByLogin: False
Caching VaryByParm: False
Caching VaryByQueryString: False
Caching VaryByUser: False


 

 

Rendering Item Name: SideMenuSimple
Rendering Item DataSource: 
Rendering ID: {92781AC5-BF07-4B3C-9D76-C436E6ABCDE5}
Rendering Placeholder: L2BSL
Caching VaryByData: True
Caching VaryByDevice: False
Caching VaryByLogin: False
Caching VaryByParm: False
Caching VaryByQueryString: False
Caching VaryByUser: False


 

 

Rendering Item Name: SiteMapsLink
Rendering Item DataSource: 
Rendering ID: {449F6899-8B93-4FE3-B669-2CF984E0EF67}
Rendering Placeholder: L2BSL
Caching VaryByData: False
Caching VaryByDevice: False
Caching VaryByLogin: False
Caching VaryByParm: False
Caching VaryByQueryString: False
Caching VaryByUser: False


 

 

Rendering Item Name: SingleSnippet
Rendering Item DataSource: 
Rendering ID: {0F7C1732-6392-4A70-9295-94481BB89E9E}
Rendering Placeholder: L2BLC
Caching VaryByData: False
Caching VaryByDevice: False
Caching VaryByLogin: False
Caching VaryByParm: False
Caching VaryByQueryString: False
Caching VaryByUser: False


 

 

Rendering Item Name: Load Demos
Rendering Item DataSource: 
Rendering ID: {E30D0753-805B-487F-95DA-D5898477F6FF}
Rendering Placeholder: L2BLC
Caching VaryByData: False
Caching VaryByDevice: False
Caching VaryByLogin: False
Caching VaryByParm: False
Caching VaryByQueryString: False
Caching VaryByUser: False


 

 

Rendering Item Name: EngagementMenu
Rendering Item DataSource: 
Rendering ID: {4230E784-E2F7-429A-82AC-A2836A887061}
Rendering Placeholder: L2BSR
Caching VaryByData: False
Caching VaryByDevice: False
Caching VaryByLogin: False
Caching VaryByParm: False
Caching VaryByQueryString: False
Caching VaryByUser: False


 

 

Rendering Item Name: DetailsMenu
Rendering Item DataSource: 
Rendering ID: {F07A0F34-A6F3-4F18-99E5-70FD41A4E83B}
Rendering Placeholder: L2BSR
Caching VaryByData: False
Caching VaryByDevice: False
Caching VaryByLogin: False
Caching VaryByParm: False
Caching VaryByQueryString: False
Caching VaryByUser: False


 

 

Rendering Item Name: Show Related Items
Rendering Item DataSource: 
Rendering ID: {5CB7C088-47D3-4E0B-A64E-58EDF851DB8F}
Rendering Placeholder: L2BSR
Caching VaryByData: False
Caching VaryByDevice: False
Caching VaryByLogin: False
Caching VaryByParm: False
Caching VaryByQueryString: False
Caching VaryByUser: False






Rendering Item Name: BottomFooter
Rendering Item DataSource: 
Rendering ID: {15CA9FFE-6A29-416C-9FF0-8734333D8A94}
Rendering Placeholder: footer
Caching VaryByData: False
Caching VaryByDevice: False
Caching VaryByLogin: False
Caching VaryByParm: False
Caching VaryByQueryString: False
Caching VaryByUser: False