The Problem
We created a new module (or component or rendering) in Sitecore and we needed to add this rendering to Allowed Controls field in the placeholder settings in Sitecore. It is also required to allow this rendering on all the placeholders in Sitecore so that content authors have the ability to add this rendering on pages in experience editor. Below is a snapshot of the field that is used for this-
If the placeholders were in limited number, it would have been an easy manual job. But we had more than 20 placeholders for different page types. And we were in a process of introducing several new modules which meant this task is going to be repetitive and time consuming. So, to save time and for accuracy, we decided that we should develop a simple PowerShell script to make this process simple.
The Solution
We developed below script -
$placeholders = Get-ChildItem "/sitecore/layout/Placeholder Settings/<path where your placeholders are present>" -recurse
Foreach($placeholder in $placeholders){
$placeholder.Editing.BeginEdit()
$placeholder.Fields["Allowed Controls"].Value = $placeholder.Fields["Allowed Controls"].Value + "|<ID of your new rendering item>"
$placeholder.Editing.EndEdit()
}
That's it. You can now run this script in PowerShell ISE and the new rendering will be added to your placeholders. You can also add conditions in above script to add renderings to Allowed Controls field of selective placeholders only.
Hope it helps you :)
Comments
Post a Comment