Skip to content

Instantly share code, notes, and snippets.

@alan-null
Last active January 20, 2018 11:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alan-null/a7dd2cd01d9d851b39a6ec5fca96ac0b to your computer and use it in GitHub Desktop.
Save alan-null/a7dd2cd01d9d851b39a6ec5fca96ac0b to your computer and use it in GitHub Desktop.
Merging Final Renderings back down into Shared Renderings
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