Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SoulOfUniverse/50be7fbb8335b929c7c79e331ac60b82 to your computer and use it in GitHub Desktop.
Save SoulOfUniverse/50be7fbb8335b929c7c79e331ac60b82 to your computer and use it in GitHub Desktop.
Convert renderings from Sitecore 8 to 9+ version
# specify your path here. It is most likely be page templates and page content
$startPath = "/sitecore/content"
Get-ChildItem -Path $startPath -Recurse | ForEach-Object {
$item = $_;
Get-Rendering -Item $_ -FinalLayout | ForEach-Object {
$rendering = $_;
$matches = [regex]::Matches($_.Placeholder,'(?<guid>_[\d\w]{8}\-(?:[\d\w]{4}\-){3}[\d\w]{12})(?<seed>_?\d?)')
if ($matches.Success) {
Write-Host "Match found in item - [$($item.Paths.FullPath)]"
Write-Host "Old Placeholder - [$($rendering.Placeholder)]"
$newPlaceholder = $rendering.Placeholder
$matches | ForEach-Object {
$match = $_
$renderingId = $match.Value
if (!([string]::IsNullOrEmpty($match.Groups["seed"])))
{
$seedSuffix = $match.Groups["seed"].ToString()
$seedValue = $seedSuffix.Trim("_")
# trim seed suffix off end
$unsuffixedRenderingId = $renderingId.ToString().TrimEnd($seedSuffix)
# add seed value to end
$newPlaceholder = $newPlaceholder.Replace($renderingId, "{$($unsuffixedRenderingId.ToUpper())}-$seedValue")
}
else
{
$newPlaceholder = $newPlaceholder.Replace($renderingId, "{$($renderingId.ToUpper())}-0")
}
}
$newPlaceholder = $newPlaceholder.Replace('{_', "-{")
Write-Host "New Placeholder - [$($newPlaceholder)]"
# comment following 2 lines if you don't want to do replacement, but want to have log of upcoming placeholder changes
$rendering.Placeholder = $newPlaceholder
Set-Rendering -Item $item -Instance $rendering -FinalLayout
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment