1

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.

6
  • Why are you assigning rendering from old to new? Why you not just copy the item and update only the template? Commented Aug 22, 2022 at 11:02
  • @SumitBhatia - The requirement is to keep the existing page as it is. And the changes to Standard value should only be applied to new pages. When I update only the template whatever rendering I have set on the new template's standard value is only getting refelected in existing pages. Commented Aug 22, 2022 at 11:07
  • Can you check if you have those standard value's presentation details in Rendering field? May be that is reflecting to final rendering? Also are you getting this behavior on all the items that you create or only few of them? Commented Aug 22, 2022 at 11:15
  • I am getting this behavior on few items. Commented Aug 22, 2022 at 11:30
  • Can you try removing renderings for those items at the end of the script of in loop? Commented Aug 22, 2022 at 11:33

1 Answer 1

0

The script you are using is only updating the template ID of the new item and the rest of the things you are assigning are the same. Like you are not updating the fields called __Renderings and __Final Rendering, rather you are passing the same value from old item to the new item.

I would recommend you to only update the template of the new item and this is a very good article here to do this.

https://blogs.perficient.com/2016/06/13/sitecore-powershell-change-item-template-and-retain-field-value/

Use the same approach and update here if you get any issues.

Hope this helps.

1
  • I have already followed this article. But this as well giving the same result. Till item 10 the renderings are copied properly from old item. Post that for all items the standard presentation details is included in Shared and Final layout. Commented Aug 22, 2022 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.