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" `
}
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.