1

I would like to get selected SXA style of the Teaser component in Powershell script.

I have a teaser component where i have selected SXA style on Experience editor . I would like to get selected SXA style of that component in Powershell script. Is it possible ?

Kindly assist me.

2 Answers 2

1

You can write this PowerShell script to find all the selected styles for any particular rendering. Enhance this script as per your requirements.

$item = Get-Item -Path "master:" -ID "{B008740C-839F-40BF-B343-84E14F6AEDC4}"
$defaultLayout = Get-LayoutDevice "Default"
#Get the Teaser Rendering by passing Placeholder Name and Item ID
$rendering= Get-Rendering -Item $item -Placeholder "*/main/container-23/row-4-12*" -Device $defaultLayout -FinalLayout
# Assuming this returns one rendering only
$dict = [Sitecore.Web.WebUtil]::ParseQueryString($rendering.Parameters)
$parameterValue = $dict['Styles'].Replace("%7B","{").Replace("%7D","}").Replace("%7C","|").Split('|')
foreach($styleItem in $parameterValue)
{
    $itemname = Get-Item -Path "master:" -ID $styleItem
    write-host $itemname.Name
}
2
  • Could you assist me how can I use the same scenario for Slick Carousel as with above code it is not getting the selected style ?
    – Nisha
    Commented Oct 4, 2022 at 12:53
  • This code should work for all rendering, just make sure you have given the right placeholder and put write-host to find out if the correct rendering is being referenced. Commented Oct 5, 2022 at 5:47
1

You can get it simply by using the Rendering Parameter on the item.

Your script should be like this.

# Get your item by ID
$item = Get-Item -Path "master:" -ID "{B485F716-9E95-42E8-8DE0-844E988A1BDF}"

# Create a loop on all the renderings of the item. 
foreach($itemRendering in Get-Rendering -Item $item -FinalLayout) {
    # Get the rendering Parameters. 
    Get-RenderingParameter -Rendering $itemRendering | Format-Table -Auto
}

You will get the rendering parameters data with Style parameters also like this.

Name                  Value
----                  -----
Navigation            {848DFE42-2B13-430E-A0B9-89CE25730A06}
Transition            {D4B706CC-7EEC-4DB9-A87D-123B29803490}
Timeout               2000
PauseOnHover          1
Reset Caching Options
GridParameters        {908E2BC6-C110-4ED7-AF39-7EEACBB31A34}
Styles                {C414B189-DAA3-4490-9B03-A7B6F4AC3A2C}|{F2A30C96-BC00-4CCD-BC1E-384744EE24C8}|{32E7E96A-17CD-4FDE-90D8-62A48B0D8BF5}
RenderingIdentifier
DynamicPlaceholderId  3

You will get the Styles ID. Now update the above logic and use Get-Item to get the field values on this item.

Hope this helps.

9
  • The documentation provides some good examples as well. doc.sitecorepowershell.com/appendix/presentation/… Commented Oct 3, 2022 at 16:18
  • Slick Carousel this code is not working
    – Nisha
    Commented Oct 4, 2022 at 12:55
  • @Nisha let me check. Are you using OOTB Carousel? And can you specify the Sitecore version? Commented Oct 4, 2022 at 12:57
  • @Nisha I tested that for the Carousel and it works. And the values that are coming in my answer are for the Carousel component. Commented Oct 4, 2022 at 13:00
  • I have added style on "Slick Carousel slide content" and it is showing nothing
    – Nisha
    Commented Oct 4, 2022 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.