Sitecore

Screencast - Introduction to SXA Rendering Variants

Tuesday, November 24, 2020
Layer One - Sr Director of Software Delivery - Phil Busch

Enable Rapid Development with Rendering Variants

We've been doing a lot of interesting work here recently that features the Sitecore Experience Accelerator (SXA). One valuable feature of SXA is called Rendering Variants. Rendering Variants allow rapid development of functionality with limited code development. Check out this screencast on an Introduction to Rendering Variants:




Transcript Hi. My name is Phil and I'm with layer one. Today I'm going to talk to you about rendering variants of feature of the Sitecore experience accelerator that allow us to take content from our content editor and display it in the markup on the pages in our site without writing any custom code. Let's dive in. I've got a page here on my site called demo page and this page is of a type that is a custom page template. This custom page template has a field on it that doesn't exist on the out of the box page template and that field is called demonstration text. If I take a look at this page right now on the live site, I won't see the content from the demonstration text on the page. This is because there's currently one rendering on the page page content, but the rendering variant that's in use is the default version that comes with Sitecore, and it does not know about this field and thus does not display. To solve this problem, I can create a custom referee ferry that displays our demonstration text field. To do this, I navigate in my site tree to the presentation area. And then I navigate to the rendering variants area where all the rendering variants are contained. Now the rendering variants are organized based on the rendering that they are compatible with. On your implementation, you may see more or less or different renderings here based on what your developer or partner has chosen. As this is the page content rendering, I'm going to add a rendering period for page content. To do that, the first thing I need to make is my variant definition, which is defines how the rendering variant is going to be identified. A name if you will. I'll call it the demo area. Now that I have a demo variant, I need to add what's called a variant field. The variant field is used to actually render the content from the data source item. In this case the page. Are in the markup on the page, so if I go ahead and I click field. I can go ahead and I can enter a name of the field. Now this is an important step. This must match the name of the field exactly on the data source that you wish to read it. In this case the page. So in our case this is called demonstration text. And now I've created a variant field. Now. Remember, we're doing this so we don't have to write any custom code, so there are some decisions that need to be made here, namely. What HTML element is going to be used to display this content? In this case, I'm going to choose an H1. The field name, which again needs to match exactly the field that you're pulling in. And there's some other things to prefixes, suffixes, link CSS, classes, things like that. This is how we define the behaviour of what's going to show up in the HTML markup. I'm going to go ahead now and I'm going to save this and I'm going to publish it so that way it's available for use on our site. Now at this variant is available for use on our site. I'm going to go ahead and I'm going to modify the page to actually use it. So now we're getting back up to my demo page here in the Sitecore tree. I'll go to the presentation details and I'll see my list of renderings on the page. I'll open up my page content control properties and I will Scroll down. To the styling section. Here in the styling section I can select my rendering variant or any other rendering variant that's available through page content on this site. I select mine demo variant and I'll go ahead and press OK and I'll go ahead and press OK again. Finally, I'll publish this to the site. So that way we can see the changes. Follow we can see our content on the page now. This is an exciting feature of the Sitecore platform. We can get this content on the page without reading any custom code, which is great for the initial development costs. It makes things make things easier. And less expensive to implement. However, we're now also enabled for very fast and rapid iteration. Additionally, the content editor could control this functionality if they so wish, and they could change the markup themselves. At layer one we do lots of cool stuff like this. If you're interested in finding out more about this and the other things we do, check out our website at layeronemedia.com.

Interested in learning more?

Contact Us
X
Cookies help us improve your website experience.
By using our website, you agree to our use of cookies.
Confirm