Uncategorized

Assigning layouts


My first idea was to write a post about the top 5 mistakes when developing in Sitecore, but then I decided to go for the one potential danger I consider grave enough for its own post: Assigning layouts to items.

A layout is basically a simple field (__layout) on an item which describes how the item is rendered by the rendering engine, and as such can be assigned on the item and on the Standard values (http://sdn5.sitecore.net/End%20User/Template%20Manager/Standard%20Values.aspx).

On pre-5.3 version of Sitecore standard values was not available, so in order to have layout reuse, layouts was assigned to templates. This functionality has been preserved in Sitecore 5.3 for backward compatibility. I’ve actually just recently been made aware of Sitecore’s recommendation on putting layout settings on standard values instead of on the template. Architecturally this is absolutely the right way to go – the template way was a hardcoded layout engine functionality to enable reuse.

Well to get back to the point: Do not – ever – assign layouts directly to items.

Assigning layouts to template standard values gives you the reuse you want and need, in order to maintain an architecturally sound Sitecore installation. Consider a situation where you have a layout (header, footer, menu, spots, content) defined on your document template, and you want to introduce a breadcrumb on your site. If the architecture is correct, this can be accomplished merely by changing the document template and all documents on your website will be updated.

Then again consider a situation where 10 specific documents need a slightly different layout. Well, the simplest way would be to just set the layout directly on these documents. WRONG! Settings layouts on directly on items primarily set aside all reuse, but more importantly makes you completely loose the overview of your solution. If you in this case wish to introduce a breadcrumb you will have to manually find (on your 10.000 page website) the items which has a specific layout and correct these – which often leads you to the painstaking realization that you have to write a script.

Therefore what you should consider is introducing data templates and layout templates and use template inheritance. In projects in Pentia, we define fields and functionality in one template then derive to another template and set the layout on this. Consider a template DocumentData which holds the fields Title and Text, and another, Document, which derives from DocumentData and define the layout (and other standard values). If I need specific layouts on certain items, I derive another layout template from DocumentData, e.g. WideDocument, which then defines the specific layout. This means that all layout settings are always in the Templates section of Sitecore – easy to find and reusable.

Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s