Created
August 30, 2017 16:45
-
-
Save AdamNaj/80fe4f86531b7c1b43bb69fd0f9cc52b to your computer and use it in GitHub Desktop.
Add SXA Tags to all SXA Pages
This file contains 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
$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