Ever got a warning on saving a Global PlaceholderSetting with the same Placeholder Key?
We had discussed about Global and Data-Template specific Placeholder Settings in the following articles:
Here, lets discuss a challenge which we might face, when configuring a Global Placeholder Setting and how to overcome that.
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.
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:
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.
Now, lets go to the Page Editor and click on the components button, to check where all can we 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.
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.
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.
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!