Modifying Rendering Parameters with Sitecore Powershell

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:

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.

Additional Info

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s