Update sitecore rendering parameters using powershell

I had a requirement to update the rendering parameter using the PowerShell script so here is the code below:

Screenshot - 1:


Here is the script:

try {
    # rendering item id for which the parameters to be changed
    $renderingId = "{3F5DE058-F909-4813-B4AA-92F940FAE5DE}"
    # Item id on which rendering is available
    $itemId = "{E4A1AD6D-A6AD-47CE-8FF1-1783EE0082CA}"
    # Get item from master Database
    $item = Get-Item -Path "master:" -ID $itemId
    # This will be used to get the rendering info from Defaul layout as in Screenshot-1
    $defaultLayout = Get-LayoutDevice "Default"
    # Get all the renderings on this item that are available on the Final Layout
    $renderings = Get-Rendering -Item $item -Device $defaultLayout -FinalLayout
   foreach ($rendering in $renderings) {
    # Check for our specific rendering
      if ($rendering.ItemId -eq $renderingId) {
           Write-Host $rendering.ItemId
           # Set the parameters in key value format, where DisplayContentInCard is the rendering parameter field name and 1 is the value because in my case this is checkbox so setting it as true
           # Same is for other rendering parameter fields ApplyBackground and AlignImageRight
            $parameters = [ordered]@{"DisplayContentInCard" = "1"; "ApplyBackground" = "1"; "AlignImageRight" = "1" }
            # Set the parameters value and update on item  
            $rendering | Set-RenderingParameter -Parameter $parameters | Set-Rendering -Item $item -FinalLayout
   
              Write-Host "$($autoInsuranceItem.FullPath) - Item Id $($autoInsuranceItem.ID) - Rendering $($rendering.UniqueID)  $DatasourceItemPath - $($rendering.Datasource)"
      }
    }
}
catch [System.Net.WebException], [System.IO.IOException] {
    $item
}


1 comment:

  1. https://sitecorepeanuts.blogspot.com/2024/07/update-sitecore-rendering-parameters.html

    ReplyDelete

Creating Solr core for sitecore using command prompt

We setup the solr cores using command “C:\solr8985\sc103solr-8.11.2\bin>solr.cmd create -c sitecore_sxa_web_index -d sitecore_configset” ...