mtelligent

View Original

View Variants for Sitecore Experience Accelerator

The ability to define varaints in SXA is a really cool feature. Allowing content authors to choose from a list of variants to choose how to render the content is intutive and slick. Out of the box, SXA allows a number of options for defining the Variant Markup, which typically requires developers to model HTML tags as Sitecore Items, which has it’s pro’s and cons, but can be unweildy for complex content structures and difficult where business rules are needed.

Previously, I’ve enabled Handlebar Templates to allow for a little more flexibility for defining variants.

Similarly, I’ve implemented a csthml view variant type if you just want to reference a view deployed to your Sitecore instance to render the content of the view. I previously blogged about this and even recorded a video of it in action here.

Where that post referenced an implementation that was part of Sitecore Foundation, I have since pulled the code into it’s own project on github: View Variants for SXA., which just has the code for this feature along with a release that includes a Sitecore Package that installs it.

This package has been tested on Sitecore 9.1 and SXA 1.8. It includes a sample variant which can be configured for the Promo component. See the read me for details.