We have set Presentation Details on template's Standard Values. I dont want these standard value renderings in my existing page, as we have correct renderings in existing pages and I want this standard value renderings on new pages created based on this template.
To achieve this I have created a new Template with Presentation Details set on template's Standard value.
I am using the following script to achieve the desired result,
write-host 'Running script...'
$rootItem = Get-Item "master:/sitecore/content/Home/test";
$sourceTemplate = Get-Item "{B3AF24FC-965A-4554-93E2-129AB3429111}";
$targetTemplate = Get-Item "{516164EF-B6BE-40F5-B63D-2CCAFBC1D570}";
$pages=Get-ChildItem $rootItem.FullPath -recurse | Where-Object { $_.TemplateName -eq $sourceTemplate.Name }
foreach($page in $pages){
New-UsingBlock(New-Object Sitecore.SecurityModel.SecurityDisabler){
New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
$renderingsText = $page["__Renderings"]
# do the same for the Final Layout
$finalLayoutText = $page["__Final Renderings"]
$page.Editing.BeginEdit();
$page.TemplateId = "{516164EF-B6BE-40F5-B63D-2CCAFBC1D570}"
$page["__Renderings"]=$renderingsText
$page["__Final Renderings"]=$finalLayoutText
$page.Editing.EndEdit();
}
}
}
The above script changes the template in all the items, but when I check the Renderings and Final renderings of the updated item they have the standard values's presentation details in few items. (i.e) Above script copies the rendering of old template properly for certain items whereas in certain items I can see the renderings from standard value's presentation detail. This is happening randomly.
I am not sure why I am facing this behavior.
Any guidance would be helpful.