There is a page template called X being used to create a number of pages. There are two renderings A and B being used on many pages that created from X page template.
Now I want to set the one rendering parameter value in Rendering B from Rendering A's datasource value. I tried to set the standard value for Rendering parameter template, however, during debugging the paramter vaule is empty.
I am unable to set the rendering parameter value. I am currently using SPE 5.0 so,
Set-RenderingParameter -Parameter $parameters
command is not working.
Below is the script I am using,
write-host 'Running script...'
$rootItem = Get-Item "master:/sitecore/content/test";
$pageTemplate = Get-Item "{D2AA238D-E7BB-48D6-1111-29BBB66B454E}";
$pages=Get-ChildItem $rootItem.FullPath -recurse | Where-Object { $_.TemplateName -eq $pageTemplate.Name }
$device = Get-LayoutDevice -Default
$Results = @();
function Set-RenderingParametersForField($item) {
$modified = $false
$renderingItem= Get-Rendering -Item $item -Device $device -FinalLayout
$bRenderingItem= $renderingItem| Where-Object -FilterScript {$_.ItemID -EQ '{21BD2323-711F-4826-AB23-999996FFB31C}'}
if($bRenderingItem -ne $null)
{
#$par = [Sitecore.Web.WebUtil]::ParseUrlParameters($_.Parameters)
#$renderingParameter = $par["RENDERING_PARAMETER_FIELD_NAME"]
$parameters = @{"Param3"="Test"}
Set-RenderingParameter -Parameter $parameters
#Get-RenderingParameter -Rendering $bRenderingItem | Format-Table -Auto
}
}
foreach($page in $pages){
$renderings = Get-Rendering -Item $page -Device $device -FinalLayout
foreach($rendering in $renderings){
if($rendering.ItemID -ne $null)
{
$aRenderingItem = Get-Item master: -ID $rendering.ItemID | Where-Object -FilterScript {$rendering.ItemID -EQ '{8E52CDC4-AA69-41DA-AAAA-D3187C581666}'}
if($aRenderingItem -ne $null)
{
if($rendering.Datasource -ne $null -and $rendering.Datasource -eq '{C27D10EA-246F-4583-A3D0-3350DD17FFFF}')
{
Set-RenderingParametersForField $page
}
}
}
}
}
write-host 'Script ended'
UPDATE:
Updated the function to get this working,
function Set-RenderingParametersForField($item , $fieldID) {
$laytoutField = New-Object "Sitecore.Data.Fields.LayoutField" $item.Fields[$fieldID]
$modified = $false
$definition = [Sitecore.Layouts.LayoutDefinition]::Parse($laytoutField.Value)
$definition.Devices | % {
$_.Renderings | Where-Object -FilterScript {$_.ItemID -EQ '{21BD2323-711F-4826-AB23-999996FFB31C}'}| % {
$par = [Sitecore.Web.WebUtil]::ParseUrlParameters($_.Parameters)
$renderingParameter = $par["RENDERING_PARAMETER_FIELD_NAME"]
if ($renderingParameter -ne $null) {
$par["RENDERING_PARAMETER_FIELD_NAME"] = "TEST"
$_.Parameters = (New-Object "Sitecore.Text.UrlString" $par).GetUrl()
$modified = $true
}
}
}
if ($modified) {
$item.Editing.BeginEdit()
$laytoutField.Value = $definition.ToXml()
$item.Editing.EndEdit() > $null
}
}