Following on from my post last month where I’ve been trying to automate some of the tedious tasks involved when building pages and components in Sitecore, I had another task which I wanted to try and automate with SPE also. This time round it was automating copying Final Renderings back to the Page Template after adding lots of components to a page in Experience Editor.
I have been building quite a few new Page Templates with between 10 and 20 components on each. I was using Experience Editor to build up the pages as it’s much quicker than using Content Editor. Once I’d finished the page I needed to ensure that all the renderings are copied back to the Page Template Standard Values Renderings field so that when Content Editors create a new page using the Template it has a default set of components. I could do this manually but is a bit tedious so I figured there must be an easier way.
I initially looked at the options available out of the box and in SPE but none of these (including the SPE Merge-Layout function) support copying renderings back to the Page Template of the item so I decided to write my own function for this.
You can call the Function as follows – note the optional -ResetLayout Switch Parameter which allows you to also reset the page you are copying the renderings from to use the Standard Values of the page template.
Import-Function Copy-Page-FinalLayout-To-Template
Copy-Page-FinalLayout-To-Template “/sitecore/content/Home/Test Landing Page” -ResetLayout
Hopefully others will find this useful when building new templates and pages and this will save you some time.
As usual there were a number of Community posts that were useful for writing this:
https://sitecore.stackexchange.com/questions/4620/copy-final-layout-to-shared-layout/4623
http://blog.martinmiles.net/post/sitecore-powershell-extension-snippets-collection