Sitecore Template Inheritance with Presentation Deltas in Standard Values

Tuesday, May 07, 2013 @ 03:09

By: Jon Upchurch, Senior Developer

I’ve been working with different CMS’s for a number of years now, and I was really excited to become Sitecore Certified and to start working with this CMS that I’d been hearing about for years but hadn’t yet been exposed to. The experience hasn’t let me down, and it’s quickly become my favorite development platform. Since I’ve recently started with Sitecore, I’ve found myself searching for articles on best practices as well as solutions to problems, and I’ve been like a sponge absorbing as much as I can.

Sitecore does a great job with Template inheritance, and the recently added Template Deltas are a great addition. In Sitecore, Presentation Details determine what Sublayouts, Placeholders, etc. will be available to a content item based on a given Data Template. These Presentation Details are inherited from the parent along with all of its other fields. When a single content item based on a template is changed, instead of breaking inheritance for this item (as it would for another field’s default values being overridden), Sitecore generates what is called a “Layout Delta”. A Layout Delta is effectively the difference between the specific item and the standard values of the parent template. If you make changes to a specific item and later change the details of the base template, the changes are thus propagated while including the one-off changes to the specific item. Neat, huh!

Sitecore is also really well put together to use nested Sublayouts. This flexibility allows for very modular and abstracted presentation which really improves development flexibility and maintainability. Everything can truly be responsible for rendering itself without caring what else is going on with the rest of the page. With this approach, you’ll see Sublayouts that contain placeholders of their own, and more content can be slotted into the page either through the use of default values for Presentation Details or by configuring the Placeholder Settings to allow Content Editors to add the content they need to onto the page.

Sitecore does a great job of this for simple sites, but for more complex sites there is a pretty serious problem in implementing this approach. The problem is that Sitecore does not generate Presentation Deltas for inherited Templates! So if I have a PageBase template that has my core Presentation Details configured in it, and I want to add a Product page, a Content page, and a Blog page that all share the base Presentation Details while having their own differences, the inheriting templates will overwrite the presentation details and break the inheritance!

This posed a bit of a quandary for me and my team. We needed to have varying templates, but wanted the maintainability of inherited templates. Even though it’s not a lot of work to update 6-7 templates if there was a change to the base, there is room for error or omission to be introduced and the chance that something would be missed is vastly increased. Also, even with good documentation a client might not know how to properly update all instances where this occurs. Searched for a solution, and found this article by Przemysław Taront - http://www.cognifide.com/blogs/sitecore/complex-layouts-in-sitecore-using-standard-values-hierarchy/.

Basically, the solution is to tap into the pipelines that Sitecore makes available, and to artificially create inherited Template Presentation Deltas. What the code does is to intercept the save event on templates and to propagate any changes made to the presentation details to its children. It generates a Delta for the child class and applies the combined Presentation Details to each child Template.

With this solution, you can implement real Template inheritance including the presentation details and truly create versatile nested layouts. I strongly urge you to check out Przemysław’s article and find the code there. It’s a good read and he provides all the code and instructions you will need to implement the idea.

Reference Source:
http://www.cognifide.com/blogs/sitecore/complex-layouts-in-sitecore-using-standard-values-hierarchy/
by Przemysław Taront