Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Copy-Page-FinalLayout-To-Template([string]$pagePath,[switch]$ResetLayout){
- #get the page item
- $item = Get-Item -Path "master:$pagePath"
- #get the final layout from the page
- $finalLayoutField = New-Object -TypeName "Sitecore.Data.Fields.LayoutField" -ArgumentList $Item.Fields[[Sitecore.FieldIDs]::FinalLayoutField]
- if ($finalLayoutField -eq $null) {
- Write-Error "Couldn't find final layout on: $($Item.Name)"
- }
- if ($finalLayoutField.Value -eq $null -or $finalLayoutField.Value -eq "") {
- return;
- }
- #get the items template and standard values on the template
- $template = Get-ItemTemplate -ID $item.ID
- $templateItem = Get-Item -Path "master:$($template.ID)"
- $templateStandardValuesPath = "$($templateItem.Paths.FullPath)/__Standard values";
- $standardValuesItem = Get-Item -Path "$($templateItem.Paths.FullPath)/__Standard values"
- #copy the final layout details back to the the renderings field on the standard values
- $finalLayoutDefinition = [Sitecore.Layouts.LayoutDefinition]::Parse($finalLayoutField.Value)
- $standardValuesItem.Editing.BeginEdit()
- $standardValuesItem["__Renderings"] = $finalLayoutDefinition.ToXml();
- $standardValuesItem.Editing.EndEdit()
- Write-Host "Template Standard Values Updated: $($templateItem.Name)"
- #reset the page final renderings back to the page templates standard values
- if($ResetLayout){
- Reset-ItemField -Item $Item -Name "__Final Renderings" -IncludeStandardFields
- Write-Host "Page Final Renderings Reset To Standard Values: $($item.Name)"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement