Last active
January 20, 2018 11:46
-
-
Save alan-null/a7dd2cd01d9d851b39a6ec5fca96ac0b to your computer and use it in GitHub Desktop.
Merging Final Renderings back down into Shared Renderings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Merge-Layout { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory = $true,Position = 0,ValueFromPipeline = $true)] | |
[item]$Item | |
) | |
process { | |
$layoutField = New-Object "Sitecore.Data.Fields.LayoutField" -ArgumentList ($Item.Fields[[Sitecore.FieldIDs]::LayoutField]); | |
$finalLayoutField = New-Object -TypeName "Sitecore.Data.Fields.LayoutField" -ArgumentList $Item.Fields[[Sitecore.FieldIDs]::FinalLayoutField] | |
if ($layoutField -eq $null) { | |
Write-Error "Couldn't find layout on: $($Item.Name)" | |
} | |
if ($finalLayoutField -eq $null) { | |
Write-Error "Couldn't find final layout on: $($Item.Name)" | |
} | |
if ($finalLayoutField.Value -eq $null -or $finalLayoutField.Value -eq "") { | |
return; | |
} | |
$finalLayoutDefinition = [Sitecore.Layouts.LayoutDefinition]::Parse($finalLayoutField.Value) | |
$Item."__Renderings" = $finalLayoutDefinition.ToXml(); | |
Reset-ItemField -Item $Item -Name "__Final Renderings" -IncludeStandardFields | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment