Skip to content

Instantly share code, notes, and snippets.

@lowedown
Created August 17, 2018 14:07
Show Gist options
  • Save lowedown/4b01e955dcb91858d9788d4bf1a137ab to your computer and use it in GitHub Desktop.
Save lowedown/4b01e955dcb91858d9788d4bf1a137ab to your computer and use it in GitHub Desktop.
String replace in Placeholder Keys
# String Replace inside Placeholder Keys
$oldPlaceholderString = "da653398-c1bc-4587-be48-0ae26b07ba9e"
$newPlaceholderString = "bfd7aec3-8655-4aff-9357-da7529754aad"
$rootItem = "master:/sitecore/content/MyHome/"
$language = "en"
$defaultLayout = Get-LayoutDevice "Default"
# Toggle for whether to update Shared or Final Layout
$useFinalLayout = $False
# If set to true, the script will only list the renderings that need fixing, rather than fixing them.
$reportOnly = $True
foreach ( $item in Get-ChildItem -Path $rootItem -Recurse -Language $language )
{
# Only interested in items that have a layout
if (Get-Layout $item -Device $defaultLayout)
{
# Get renderings in this item that have renderings in the placeholder we want to update
$renderings = Get-Rendering -Item $item -Device $defaultLayout -FinalLayout:$useFinalLayout
foreach ( $rendering in $renderings )
{
if ($rendering.Placeholder -match $oldPlaceholderString)
{
$oldPlaceholder = $rendering.Placeholder
$newPlaceholder = $rendering.Placeholder -replace $oldPlaceholderString, $newPlaceholderString
# Only update the rendering if we're not in "Report Only" mode
if (!$reportOnly)
{
# Update the placeholder in the rendering and set it back in the item
$rendering.Placeholder = $newPlaceholder
Set-Rendering -Item $item -Instance $rendering -FinalLayout:$useFinalLayout
}
Write-Host "$($item.FullPath) - Rendering $($rendering.UniqueID)"
Write-Host " $oldPlaceholder"
Write-Host "--> $newPlaceholder"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment