Okay, so we all know the difference between Renderings and Final Renderings right? Final renderings were introduced in Sitecore 8 to make it possible to have different layouts for the various language and versions of an Item. Awesome!!
- __Renderings – a shared field where you specify the common layout for all languages and versions of the item.
- __Final Renderings – a versioned field where you specify individual layouts for languages and versions of the item.
I ran into an issue where I needed to modify the __Final Renderings for specific templates. A parameter of a component for a specific language in use on a site, needed to be updated.
For tasks like this Sitecore Powershell Extensions is your best friend. Special thanks to Adam Najmanowicz and Michael West for their continued work on this awesome tool. There are a few approaches you could take to achieve this:
Approach 1
Using this approach we get all the items by language and template, traverse the items and do a string replace on the __Final Renderings field value. This approach gets the job done. However, it has to check the __Final Rendering field of every item to see if the string to be replaced exists or not. Depending on the number of items you need to update it might be rather slow.
Approach 2
This approach is rather more elegant as it uses the SPE Get-Rendering command to retrieve the rendering instance and the Get-RenderingParameter command to retrieve the parameters for the instance. Once you have the parameters you can modify them then use Set-RenderingParameter and Set-Rendering to save the parameters and the rendering. This approach gives you fine-grained control over the renderings and parameters that are updated as the filtering allows you to target renderings used within specific placeholders, using specific parameters, etc.
The SPE documentation contains some useful examples working with Renderings:
- Update Rendering Parameters
- Find Pages using a rendering
- Find Renderings with personalization
- Move Renderings between placeholders
- Remove Datasource from rendering
- Replace compatible rendering
It is probably a good idea to try and keep up-to-date with the latest version of SPE. You can review the release notes and check out the different enhancements and fixes that have been added.
Adam Seabridge has written a really good article demonstrating swapping and deleting renderings with SPE.