Skip to main content
1 of 2
R. Allinson
  • 511
  • 2
  • 13

Sitecore Powershell - Getting and setting the order of renderings/sublayouts on a page

I have written a PowerShell script that replaces sublayouts with renderings across all pages in a Sitecore site. Everything is working well except for the order of the renderings. The order always follows the order of the sublayouts in the page layout not the actual order seen in Experience Editor.

Does anyone know how I can get the order of the sublayouts and then apply that to the new renderings?

I read that the rendering 'index' can be used to get and set the order but when I run this script on a page the index always returns as null for all renderings:

$device = Get-LayoutDevice -Default
$database = "master" #master|web
$path = "$($database):/sitecore/content/home"
$item = Get-Item -Path $path

$finalRenderings = @(Get-Rendering -Item $item -FinalLayout -Device $defaultDevice)

foreach($rendering in $finalRenderings) {
    Write-Host "Rendering Placeholder: " $rendering.Placeholder
    Write-Host "Rendering Index: " $rendering.Index

    $renderingItem = Get-Item $rendering.ItemID
    Write-Host "Rendering Name: " $renderingItem.DisplayName
}
R. Allinson
  • 511
  • 2
  • 13