How we Identifying and modifying custom Renderings parameter by PS script
In the world of Sitecore SXA, development, and maintaining data integrity are crucial to deliver a seamless and engaging user experience. In this blog post, we’ll explore a practical approach using PowerShell Extensions (SPE) to verify Renderings and modify their parameter using PS for avoiding manual efforts.
Content authors often create and manage numerous renderings, which are components responsible for displaying content on web pages. However, over time, some renderings required some modification like enabling cache/ Or any other rendering parameter in the layout definitions.
By using SPE we can address the challenge of “modifying parameters”. The script we’ll discuss helps identify and modify parameters from the layout definitions, improving the data integrity of your Sitecore implementation.
The PowerShell script utilizes the Get-Rendering command from SPE to retrieve the target item. It then examines the layout definition and iterates through the renderings associated with the item. For each rendering, the script verifies the paramter. If "Ajax Call" parameter is detected, then it is modified.
$renderingParamterToUpdate = "Ajax Call"
$newRenderingParameterValue = "0"
foreach($language in $languages){
$items = Get-ChildItem -Path $startPath -Language $language -Recurse
foreach($item in $items){
Write-Host 'Updating Item: ' $item.Paths.FullPath
foreach($itemRendering in Get-Rendering -Item $item -FinalLayout) {
$renderingItem = Get-Item -Path master: -ID $itemRendering.ItemID
if($renderingNames -contains $renderingItem.Name){
Write-Host 'Found Rendering: ' $($renderingItem.Name)
$parameters = Get-RenderingParameter -Rendering $itemRendering
if($parameters[$renderingParamterToUpdate] -ne $newRenderingParameterValue){
Write-Host 'Updating' $renderingParamterToUpdate -ForegroundColor Green
$parameters[$renderingParamterToUpdate] = $newRenderingParameterValue
$itemRendering | Set-RenderingParameter -Parameter $parameters |
Set-Rendering -Item $item -FinalLayout
}
}
}
}
}
Comments
Post a Comment