Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add SXA Tags to all SXA Pages
$sitePath = "master:\content\Demo\Origin"
#get items but only those that are SXA pages
$pages = Get-ChildItem "$sitePath\Home" -Recurse -WithParent |
Where-Object { Test-BaseTemplate -Item $_ -Template "Foundation/Experience Accelerator/Multisite/Content/Page" }
#you can pipe it to further filtering here if you want to do it only for some pages
#get tag items that contain the word "Adam" in them
$tags = (@() + (Get-ChildItem "$sitePath\Data\Tags" -Recurse |
Where-Object { Test-BaseTemplate -Item $_ -Template "Feature/Experience Accelerator/Taxonomy/Datasource/Tag" } |
Where-Object { $_.Name -like "*Adam*" })).ID
if($tags.Count -gt 0){
foreach($page in $pages){
#for every page add the tags - make sure they are uniquely used and tags are not added twice.
$page.SxaTags = (@() + $page._.SxaTags.GetItems().ID + $tags | select -Unique) -join "|"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.