Created
June 9, 2025 03:17
-
-
Save MartinMiles/ce21206a7368ceb46d95a6e2f3a8e6e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[string] $PlaceholderKey = "col-wide-2" | |
) | |
# 1) Load master database | |
$db = [Sitecore.Configuration.Factory]::GetDatabase("master") | |
if (-not $db) { | |
Write-Error "ERROR: Could not load the 'master' database." | |
exit 1 | |
} | |
# 2) Known IDs | |
$fieldId = [Sitecore.Data.ID]::Parse("{7256BDAB-1FD2-49DD-B205-CB4873D2917C}") | |
$templateId = [Sitecore.Data.ID]::Parse("{5C547D4E-7111-4995-95B0-6B561751BF2E}") | |
# 3) Get the Placeholder Settings folder | |
$rootItem = $db.GetItem("/sitecore/layout/Placeholder Settings") | |
if (-not $rootItem) { | |
Write-Output "ERROR: '/sitecore/layout/Placeholder Settings' not found." | |
exit 1 | |
} | |
# 4) Pull all descendants into an array | |
$allDesc = @($rootItem.Axes.GetDescendants()) | |
# 5) Filter by template + field value | |
$matches = @( | |
$allDesc | | |
Where-Object { | |
$_.TemplateID -eq $templateId -and | |
$_.Fields[$fieldId].Value -eq $PlaceholderKey | |
} | |
) | |
# 6) Output based on how many we found | |
switch ($matches.Count) { | |
1 { | |
# Exactly one match: output its ID | |
Write-Output $matches[0].ID | |
} | |
0 { | |
# No matches | |
# Write-Output "No placeholder-definition found for key '$PlaceholderKey'." | |
} | |
default { | |
# More than one | |
$ids = $matches | ForEach-Object { $_.ID } -join ", " | |
Write-Output "Multiple definitions found for key '$PlaceholderKey': $ids" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Returns the ID of found placeholder definition item (or nothing at all)