October 28, 2024

Ever got a warning on saving a Global PlaceholderSetting with the same Placeholder Key?

Sitecore-Placeholder-Setting

Introduction:

We had discussed about Global and Data-Template specific Placeholder Settings in the following articles:

https://varunvns.wordpress.com/2014/07/03/placeholder-settings-empower-your-page-editor-users/

https://varunvns.wordpress.com/2014/07/07/placeholder-settings-empower-your-page-editor-users-part-2/

Here, lets discuss a challenge which we might face, when configuring a Global Placeholder Setting and how to overcome that.

Challenge:

As we know, a Global Placeholder Setting, is a one with a Placeholder key assigned to it. So whenever a PageEditor user want to add a component to a page, they can go to the PageEditor aka Experience Editor and go to any particular Placeholder and add the configured component for that particular Placeholder, with help of Placeholder Setting. I am sure you might have referred to this article mentioned above, but in case you missed it, check it out for  details.

Now, whenever we have two Global Placeholder Settings with the same key, Sitecore warns us right at the time when we set the key to be the same but if we ignore it, this is what happens. Sitecore always applies the first PlaceholderSetting out of the two in the list with a given placeholder key.

Example:

I have installed a Sitecore solution which comes with a Global placeholder setting called content – /sitecore/layout/Placeholder Settings/content with the Placeholder Key as “content”. This is how it looks:

Sitecore-Placeholder-Settting

As we see above, the Allowed controls set in the setting is Sample Rendering.

Now, I create a new Placeholder Setting called My content, with the same Placeholder key as “content”. I will create it in a folder called A, so that it stays above the content Placeholder Setting, we just saw.

 The Allowed controls, as we see above are Sample Sublayout and Sample Datasource Sublayout.

Now, lets go to the Page Editor and click on the components button, to check where all can we add a new component.

Sitecore-Add-a-New-Component

 

As we see, there is availability of adding new components to the content Placeholder key — Lets click on Add to here button.

Sitecore-My-Placeholder-components

 

If we check, these are the components of My Content Placeholder Setting. Now, let me rename the folder A to Z — so that it moves below the content (/sitecore/layout/Placeholder Settings/content) Placeholder Setting. Now, lets go to the Page Editor again, click the Add a New component button and click on Add to Here of content Placeholder.

Sitecore-content-Placeholder-Setting-after-Folder-rename

And, what we find is, the Placeholder Setting  content (/sitecore/layout/Placeholder Settings/content) is applied.

Why is this happening?

Maybe because Sitecore considers the first Global Placeholder Setting with a given Placeholder Key and applies it to our website.

The biggest question that arises in our mind is When we might face such a case?

Well, such a case will generally not occur in a single-website instance of Sitecore. It can mainly occur in a multi-site Sitecore solution, say we have a Placeholder Setting called “Header-Setting” with the assigned Placeholder key as “header”  for more than one sites in the same Sitecore solution. In that case, Sitecore will always consider the 1st PlaceholderSetting for a Placeholder Key and not the site specific Placeholder Setting.

Solution:

Firstly, its always good to have Placeholder Settings, as we know it empowers the Page Editor users. So lets not think of removing it from our Sitecore solution.

Instead, lets create Global Placeholder Settings with a site-specific Placeholder Key, so that it doesn’t clash/collide with other Placeholder Setting. Next, if we have Global Placeholder Settings, and we link them with the content items i.e. ideally in the Standard values of templates, for all those items where that particular Placeholder Key might appear, we will never face such an issue. Or else, lets always create a Template-specific Placeholder Setting rather than a Global Placeholder Setting.

Lastly, Sitecore is an awesome solution and it even gives us great validation messages. So we need to be careful enough to read and understand them and work accordingly. If we do that, we will never ever face this issue!

Happy Sitecoring!

1 thought on “Global Placeholder Settings – Why a unique Placeholder Key is important

  1. Good post Varun. While the following doesn’t change anything information, it is tangentially related, and it might be useful for anyone who’s looking to have a single Placeholder Settings item relate to multiple instances of that placeholder on a single Page (via Dynamic Placeholders concept).

    We created the Integrated Dynamic Placeholders Module (https://marketplace.sitecore.net/Modules/Integrated_Dynamic_Placeholders.aspx?sc_lang=en) as a way for developers to easily incorporate Dynamic Placeholders into their solution (using either WebForms or MVC), but also to allow for a one-to-many relationship to exist between Placeholder Settings items and the actual representations of the (dynamic) placeholder that may exist on a page. Without this module (or your own custom code), if you use Dynamic Placeholders, you need to create an explicit placeholder setting item for every representation of the placeholder that may end up rendering on a page. This can be a maintenance time-waster, and was the main motivation behind our module.

Leave a Reply

Your email address will not be published. Required fields are marked *