Skip to content

Instantly share code, notes, and snippets.

@AlexKasaku
Created November 10, 2016 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexKasaku/7b5ae6803fc1aa47fca1ec546e76b3fa to your computer and use it in GitHub Desktop.
Save AlexKasaku/7b5ae6803fc1aa47fca1ec546e76b3fa to your computer and use it in GitHub Desktop.
Change template without breaking layout
$item = Get-Item -Path master: -ID "{C7FF7164-CECC-44A5-9A16-784619578316}"
$sharedLayout = $item.__Renderings
$finalLayout = $item."__Final Renderings"
if ([Sitecore.Xml.Patch.XmlPatchUtils]::IsXmlPatch($finalLayout))
{
$finalLayoutFull = [Sitecore.Data.Fields.XmlDeltas]::ApplyDelta($sharedLayout, $finalLayout)
}
## Change template
Set-ItemTemplate -Item $item -Template "/sitecore/templates/User Defined/NewTemplate"
# Reget item
$item = Get-Item -Path master: -ID $item.ID
## Layout will be broken now, so work out a new patch delta between the finalLayout and the new sharedLayout
if ($finalLayoutFull) {
$delta = [Sitecore.Data.Fields.XmlDeltas]::GetDelta($finalLayoutFull, $item.__Renderings)
$item."__Final Renderings" = $delta
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment