I need to transfer not full layout only some common renderings from the Final layout to the Shared layout in the presentation details section for over 100 pages in Sitecore 10.2.
I've attempted to write a PowerShell script for this task, but it's not working correctly. Could someone provide guidance on the proper approach or help troubleshoot my script?
param(
[string]$itemPath = "/sitecore/content/Home", # Path to the item
[string]$renderingName = "CommonRendering" # Name of the rendering to move
)
# Get the target item
$item = Get-Item -Path $itemPath
if (-not $item) {
Write-Host "Item not found at path: $itemPath"
return
}
# Access the default layout device
$defaultLayout = Get-LayoutDevice -Default
# Get renderings from the Final layout
$finalRenderings = Get-Rendering -Item $item -Device $defaultLayout -FinalLayout
# Find the rendering to move
$renderingToMove = $finalRenderings | Where-Object {
$_.RenderingItem.Name -like "*$renderingName*"
}
if (-not $renderingToMove) {
Write-Host "Rendering '$renderingName' not found in Final Layout."
return
}
# Remove rendering from Final Layout
Remove-Rendering -Item $item -Rendering $renderingToMove -Device $defaultLayout -FinalLayout
# Add rendering to Shared Layout
Add-Rendering -Item $item -Rendering $renderingToMove -Device $defaultLayout -SharedLayout
Write-Host "Rendering '$renderingName' successfully moved from Final to Shared layout."
I have tried with this question but this is not working in my case.
Copy final layout to shared layout
In my case I need to transfer not full layout only some common renderings from the Final layout to the Shared layout.