Placeholder Settings make the world go round.  Unfortunately, out of the box Placeholder Settings have some limitations.  While it’s true you can create a generic placeholder setting and then override it at the template level.  Sometimes you may have dozens of “common” components that you want on every template.  If you’ve tried to add a generic AND template-specific placeholder setting to a standard values before, you know that Sitecore picks the first one.  It doesn’t have a concept of merging.  If you have a new component that is common to all templates, you need to add it to all template-specific placeholder settings.  This can be a tiring pain, and leaves room for errors.

Enter in: Composite Placeholder Settings.

First, we’re going to create a new template in Sitecore that will inherit from Placeholder Settings.  In this template, we’ll add a new field to allow for the selection of other Placeholder Settings.

TemplateItemCPS

(We’re also going to create a folder template and stick that in the Placeholder Settings Folder).

Now you can insert new Composite Placeholder Settings in the Placeholder Settings folder.

InsertOptionsCPS

Our template functions exactly the same as a normal Placeholder Setting, but has that one additional field, Base Placeholder Settings.

ItemshotCPS

In this example, our Composite Placeholder Setting will inherit all the Placeholder Settings for ‘main 2’ and ‘Main’, as well as the addition of the ‘Staff Listing Accordion’.  How’s the code look for this?  Glad you asked!

Sitecore uses a pipeline called getPlaceholderRenderings which includes a method for returning all the renderings listed in the associated Placeholder Settings.  Here’s a dotPeek view of the method.

That’s pretty straight forward.  Find the Allowed Controls field and grab all the items inside.  We’re going to leverage this and take it one step further:

All we’ve done here is inherit from Sitecore’s default method, and overridden the GetRenderings.  We use the Sitecore method to grab any renderings for the Composite, and then iterate through all base settings and merge it into a list. Finally, we return just the distinct values back.  That’s not bad at all.

Here’s the patch to replace the default processor.

There you have it.  If there are any questions about this, drop a comment!

Facebooktwittergoogle_plusredditlinkedinmail