Placeholders in a Sitecore Multisite Solution
No longer are the days of Sitecore where developers stack the presentation layer and that is the page the author writes content for. With the addition of the page editor, the content author can take on a much larger design role. One page type can now be stretched to create much more custom pages with a little planning and some creativity. But along with this flexibility there are some complexities to consider. Before we talk about a multi-site solution, let's take a step back and talk about placeholder settings in general. The placeholder settings folders is located at the root of the Layouts folder. Inside here you can create a placeholder item which is fairly simplistic. If you populate the Placeholder Key field with your placeholder, and layouts / renderings placed in the Allowed Controls field will be accessible by the content author to insert. Furthermore on each layout / rendering we want to allow we can identify the Datasource Location and Datasource Template on that item to allow the author to relate data to the control. Now in a multi-site solution you will plan to allow your authors to insert controls, but where the problem comes into play is when two sites share the same placeholder name. We usually generalize our placeholder naming structure to the point where names like "content", "main", "left", or "right" are fairly common. This scenario could result in authors gaining access to controls meant for other sites. But this is fine, as there is a step up to making this work. First of all get rid of the idea of using the "Placeholder Key" field. Unless you can identify something global enough that it will always span every site in your solution, this field should never be populated. Instead we will attach the placeholder settings specific to our page type templates. Here is a step by step approach to adding ControlX to placeholder "content" for SiteX:
- Under Placeholder Settings folder, create another Placeholder Settings folder and call it "SiteX". This gives us division for organizing. We assume you are creating a naming convention like this already for other areas of the sitecore structure. So use the naming convention and structure you are most comfortable with.
- Inside Placeholder Settings/SiteX create a Placeholder Settings item and name it "content".
- On our new item "content", leave the Placeholder Key blank, but add the control "ControlX" under the allowed controls. Make sure editable field is checked on, and add a description if necessary.
- Finally under each page type template, open Presentation > Details, edit, and select the Placeholder Settings tab. From here you can add the placeholder settings item and add it to placeholder content.
The biggest take away from this is that in a multi-site solution, 99% of the time you would not want to use the Placeholder Key field on the Placeholder Setting item. In fact I always go into the mindset that a single site could turn into a multi-site down the road, so it is probably just best to start adding Placeholder Settings items to your page templates, versus using the global Placeholder Key field for managing what your authors can insert. Finally I prefer to name my Placeholder Settings items the same as what placeholder they will be used against. This works in most cases, but hold on to the idea that a common placeholder could need different settings items for different page types to allow for different ranges of allowed controls. In our example above the "content" Placeholder Settings item could have variations of "oneColumnContent" and "twoColumnContent" to support controls that meet the different layouts.