0

I need to change the template of multiple items in a folder but need to retain the field values and rendering and layout details. I was able to change the template and retain the field values. But how do I retain the renderings and layout after changing the template? I have tried the following,

Method 1:

SourceTemplate={00000-00000-0000}
$master = [Sitecore.Configuration.Factory]::GetDatabase("master");
$entryTemplate = $master.Templates["MyTemplate/TemplateToChange"];
Get-ChildItem -recurse | ForEach-Object { if ($_.TemplateName -eq sourceTemplate) { $_.ChangeTemplate($entryTemplate) } };

Method2:

Set-ItemTemplate -Item $_ -TemplateItem $targetTemplate `
    -FieldsToCopy @{ `
        "__Renderings" = "__Renderings" `
        "__Final Renderings" = "__Final Renderings" `
    }

enter image description here Have added above code in image for reference, In Method 1, the renderings are not copied at all. In Method 2, though the renderings are copied the datasources are not copied properly. This is happening randomly and not to any particular item in the path.

2
  • Fields values should be copied automatically. Compare side by side your fields before and after you change template. Other thing to check are Standard Values for both templates - do they define any presentation? Commented Nov 29, 2021 at 20:35
  • Field values are getting retained. The main issue here is the Rendering. In the Target template we have the Standard values similar to what we have in SourceTemplate. Commented Nov 30, 2021 at 6:27

0

Your Answer

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

Browse other questions tagged or ask your own question.