Created
November 10, 2016 17:18
-
-
Save AlexKasaku/7b5ae6803fc1aa47fca1ec546e76b3fa to your computer and use it in GitHub Desktop.
Change template without breaking layout
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
$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