Monday, February 25, 2019

Assigning a rendering variant to a custom SXA rendering

We had to clone an existing SXA component and use it with custom HTML and Styling. In our case, we chose the carousel component as we needed an ability to add Tiles the way we add slides in the carousel SXA component.

Carousel component uses Page Content (/sitecore/layout/Renderings/Feature/Experience Accelerator/Page Content/Page Content) rendering for the Slide which uses Rendering variants for rendering the components.

I had to clone the Page Content rendering also as the mark-up it used didn't match our designs. Now the problem I faced is that the "clone of the Page Content" rendering was not able to find its rendering variants. BTW, here I should mention that the Rendering Variants are expected to show up in a drop down of the component properties which is based on {936D40D8-E317-4A33-9F66-E65E9FF51845}.

After getting deeper into this problem I found how the rendering variants are populated for a rendering. It is based on the getVariants pipeline which in turn calls four processor's as shown in the snapshot below. You can see this in the showconfig.aspx


Below is what each processor of this pipeline does:

1. First processor looks for System Variants under {F9814DDD-B646-469D-9E22-E0E867730B7B} which is /sitecore/system/Settings/Foundation/Experience Accelerator/Rendering Variants/Rendering Variants. Where is looks for variants under variant definition which has the same name as the rendering item

2. Second processor looks for Site variants under /sitecore/content/Sitecore/[Site name]/Presentation/Rendering Variants/{Rendering Name}

3. Third, based on the compatible rendering mentioned in the rendering variant

4. Fourth, it says GetSharedVariants. I am not too sure about this processor at the moment but I would come back and edit this post once I find out.

Ideally, I would have preferred the 2nd option to work so that I can keep the rendering variants grouped by the site but somehow it didn't but the first option worked. So now I have my custom rendering variant under /sitecore/system/Settings/Foundation/Experience Accelerator/Rendering Variants/Rendering Variants

No comments:

Post a Comment