Layout Settings

Layout Settings


  • The highest-level presentation object in the Sitecore presentation stack
  • An .aspx file type (Web Form)
  • Starts with a page directive that specifies the language and the location of the associated code for the page
  • Defines the presentation elements that persist across all Sitecore requests for a particular device (defines the overall page )
  • Can contain all controls and placeholders
  • Typically provides the site header and footer
  • Developers typically create one layout per device
  • Only one can be assigned at a time in Presentation Layout Details

Layout Attributes

  • DefaultLayoutFile is the path to the layout file to use for items that do not specify a layout file themselves. Default value is an empty string
  • LayoutFolder is the default location of layout files (.aspx) and user controls (.ascx). The system will monitor this folder for changes and reload the appropriate caches. The default setting is /layouts. The value can be a virtual or physical path
  • LayoutNotFoundUrl is the Url for page handling of 'Layout not found' errors
  • LayoutPageEvent is the name of page event where the layout pipeline will be run. The three valid values are 'preInit', 'init', and 'load'.  Default value is: 'preInit'

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Configuration.Settings
  • Sitecore.Context
  • Sitecore.Data.Items.Item

Layout Configuration Settings

  • <configuration>
    • <sitecore>
      • <settings>
        • <setting name="DefaultLayoutFile" value="training.aspx"/>
        • <setting name="LayoutPageEvent" value="preInit" />
        • <setting name="LayoutFolder" value="/layouts" />
        • <setting name="LayoutNotFoundUrl" value="/sitecore/service/nolayout.aspx" />

Layout Settings C# Web Control Code

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

string defaultLayoutFile = Sitecore.Configuration.Settings.DefaultLayoutFile;
string layoutFolder = Sitecore.Configuration.Settings.LayoutFolder;
string layoutNotFoundUrl = Sitecore.Configuration.Settings.LayoutNotFoundUrl;
string layoutPageEvent = Sitecore.Configuration.Settings.LayoutPageEvent;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.Write("C# Web Control Real-time Output");

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
//using &#58; for colon and &#160; for space
output.Write("{0}&#58;&#160;{1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

output.Write("{0}&#58;&#160;{1}", "Default Layout File", "<b>" + defaultLayoutFile + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Layout Folder", "<b>" + layoutFolder + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Layout Not Found Url", "<b>" + layoutNotFoundUrl + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Layout Page Event", "<b>" + layoutPageEvent + "</b>");
output.RenderEndTag(); //Div

Layout Settings C# Web Control Output

Default Layout File: 
Layout Folder: C:\inetpub\wwwroot\TIC66Live\Website\layouts
Layout Not Found Url: /sitecore/service/nolayout.aspx
Layout Page Event: preInit