Take control of your sublayouts

There are several options available when setting up which data feeds into your sublayouts or renderings within Sitecore. Typically we work with sublayouts since they fit the programming style used in-house.

When you add a presentation component to a page you can configure data in a manner of ways:

In this example we have setup rendering parameters for ‘Section Image Header’ (the items that feed this dropdown are content items elsewhere in the content tree). Alternatively you can explicitly set the ‘Data Source’.

When coding your sublayouts, its simple to extract information from either the rendering parameters or the ‘Data Source’ field using the following examples.

To then access the ‘Section Image Header’ rendering parameter you could query:

One disadvantage with using parameters to setup the data into sublayouts is that the links database doesnt honour the relationship. See where is shared content used for help with this.

Rather than needing the code shown above in every sublayout you can create a base classes to expose the data source and parameters as properties and methods:

Another tip to consider, you can setup your sublayouts with an attribute to automatically use the rendering parameters as the sublayouts data:

In this example the sublayout will know to take its data from the item related in the ‘Section Image Header’ rendering parameter.

Leave a Reply

Your email address will not be published.