Get Sublayouts

Get Sublayouts

Sublayouts

  • Define a presentation area used to render output on a page
  • Contain markup substructures shared to multiple pages
  • Can further nest components dynamically using placeholders in sublayouts
  • Can contain reusable groups of controls, such as a header sublayout that developers bind to multiple layouts that share a common collection of controls

Sublayouts C# Web Control Code

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

string query = System.String.Format("//*[@@templateid='{0}']", Sitecore.TemplateIDs.Sublayout);

Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Data.Items.Item[] descendants = db.SelectItems(query);
if (descendants == 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 displayName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using : for colon and   for space
output.Write("{0}: {1}", "Item", displayName);
output.RenderEndTag(); //P

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
output.Write("{0}", "Displaying Ten Filtered Descendants");
output.RenderEndTag(); //P

int i = 0;
foreach (Sitecore.Data.Items.Item descendant in descendants)
{
    i++;
    output.Write("{0}", descendant.DisplayName + "<br/>");
    if (i >= 10) break;
}

output.RenderEndTag(); //Div


Sublayouts C# Web Control Output

Displaying Ten Filtered Descendants

Sample Inner Sublayout
Sample Sublayout
CopyFieldValues
UpdateInfoContent
UpdateItemProperty
UpdateRichTextField
UpdateTextField
Culture Information
DropDownLists
Label Controls