Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fluxdigital/c4722a4a625440f14b7810793fffd40f to your computer and use it in GitHub Desktop.
Save fluxdigital/c4722a4a625440f14b7810793fffd40f to your computer and use it in GitHub Desktop.
add-experience-editor-button-to-rendering.ps1
#add button to custom experience editor button to all matching components
$componentsPath = Get-ChildItem -Path "/sitecore/layout/Renderings/Shared/Test"
$multiListFieldName = "Page Editor Buttons"
$buttonIdToAdd = "{26A25CDD-E49D-4846-BA07-17D85C6DA950}"
Write-Host "Getting Components..."
foreach($component in $componentsPath){
#check if there is no datasource
if($component.Fields["Datasource Location"].Value -ne ""){
[Sitecore.Data.Fields.MultilistField]$buttonField = $component.Fields[$multiListFieldName]
Write-Host "$($component.Name) - Buttons: $($buttonField.GetItems().ID)"
$component.Editing.BeginEdit()
$component.Fields[$multiListFieldName].value = (@() + $($buttonField.GetItems().ID) + $buttonIdToAdd | Select-Object -Unique) -join "|"
$component.Editing.EndEdit()
}
else{
Write-Host "$($component.Name) - no datasource so skipping" -ForegroundColor "Red"
}
}
Write-Host "---Script Completed---" -ForegroundColor DarkCyan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment