Sitecore: Inheritance of Presentation Details
When developing websites there is usually the requirement that, in addition to the individual contents of the respective sites, specific elements should always be present.
The goal is to assign these global elements to the respective display areas only once, for example in order to relieve editors from the task of having to integrate the logo, navigation, etc. into their newly created website, in addition to the actual specific contents. Moreover, this way you have the option to change the global layout and its contents centrally, for instance to insert relevant teasers in the course of a campaign or current news.
For this purpose the layout is divided into a grid, which is made of the areas for the global elements ‘header’, ‘navigation’, ‘footer’ and a ‘content’ area for the individual page content.
All pages of the website are based on the same global template, called ‘document’. The allocation of the elements ‘header’, ‘navigation’ and ‘footer’ happens on the level of the standard values for this template in the presentation details.
For the actual page content you now create a new template, a ‘DocumentContent’, and a respective sub layout. This sub layout divides the content area again and adds an area for the display of current news. This should be visible on most pages, but not on all. The pages, that should display news, are based on a new template; for all other pages you can continue to use the ‘Document’ template.
The ‘DocumentContent’ template uses the ‘Document’ template as the base, so it inherits the configuration of the presentation details, in which the assignment of the global elements happened. At least this is what you would expect. In reality the configuration of the presentation details in the ‘DocumentContent’ template leads to on overwriting, so to speak, of the configuration of the presentation details in the ‘Document’ template. The result is that the actually globally configured elements aren’t displayed.
For the desired performance to happen you have to interfere with the process that causes the display of the pages. Here the presentation details of the templates have to be combined in a way so that no information gets lost. This is possible without any problems in Sitecore.
In order to link into the rendering process you have to define an appropriate processor or two in a configuration file, which will be located under App\Include:
The first processor serves as an indication if the presentation details should be passed on for a particular template. For this purpose a new layout called ‘Inherit’ is created in Sitecore and is used in the templates that should get processed accordingly.
With the help of the second processor the presentation details of the various inheritance levels are combined by running through the configurations of the inherited templates.
The homepage will now be configured in a way that it uses the ‘Inherit’ layout. Additionally, the placeholders with the content elements ‘News’ and ‘Flexslider’ are used:
With this step we have created a new page type, which can be used at any desired position. This way, additional page types can be implemented without having to change the global layout. And the requirement of having to configure the global elements only once - i. e. header, navigation and footer - is covered this way as well.
The fact that there is no dedicated mechanism for the inheritance of presentation details in Sitecore, but that the area for storage of this information is treated the same way for inheritance as with all other data areas, is quite a flaw. In practice you will not get around a relevant solution in order to be able to handle the configuration of a complete website.
Here at Cocomore we have discovered and fixed this deficiency early on. The presented extension is part of our Sitecore library and can be helpful for any project.