Skip to main content

SXA decision making on different rendering approaches and components

Hi Team,

I am taking a break from a COVEO series for sometime, I will still finish up all of them this year so we have end-to-end guide for it like a crash course

Today, I would like to draft something which I have been asked many times, as well as many of us working with SXA must have came across, the question of "How to decide what kind of option one should choose out of so many option available in SXA, like view over riding, rendering variants, OOTB components, cloned components, Custom components" which one should be used and when is a very common question you all must have came across, I thought to write my view here to simplify the understanding of each and will put it on you end users to decide which one should be selected and when.

Though, The purpose of this blog post is to give brief understanding of which does what and you can cross check with your business need and take the decision, I have experience of working with all of the  following different types and ways of SXA so I will just provide you real life scenarios too, so you can compare it with your business case at hand. 

Overriding view



This setting is available under your settings item under the site node, i.e "/sitecore/content/<<Tenant>>/<<Site>>/Settings" and there is a field called "Custom rendering view path"

Beauty of this field is if you have a requirement only to modify the view of existing OOTB SXA, for example if you just want to add some custom mark up to any existing component like promo or any other OOTB component, via this field what you can do is, you can give path to your custom view folder and .cshtml path (name of the component should be same as OOTB component), so now while rendering SXA engine will check if there are any custom folder path defined in this field, it will try to render the view from that location instead of existing OOTB SXA view path, this should be used only when you want existing component's repository and model and everything to work "as-is" but somehow you just want to change the view, so all the business logic of existing component will work "as-is" only HTML will be served from the custom view path folder that you gave.

Here, even if you upgrade SXA, it will update its existing views, your custom view path folder and the view inside it will still be intact, hence you will not loose anything even if you upgrade.

NOTE: Only thing in above approach is for example if you have created custom html view for promo component, so SXA will replace this custom html site wide, if you have a requirement where you want existing promo as well as and another component with little different html structure on other pages, then following is an option.

Rendering Variant

As said above, if you have a requirement where existing component's fields are satisfying your need for your component but you want different variation of same component on different pages, at that time you should create the rendering variants, they are just responsible to create the desire HTML structure from the data source given, you can create completely new type of HTML structure which will get render when you select the variant from editor, Provided the fields that you refer are matching with the OOTB's template and data source is set.

Also rendering variant helps when you kind of have lopping mechanism, so for instance if you have one Author component which displays author bio and blogs written by that author in same component, this type of requirement can also be achieved using variants, It all depends on what kind of template you have used, so if you are identifying blogs written by authors using multi list (using field source), you can use "passthrough field" of variant, so blogs will be your reference field so SXA will when generating HTML for author, it will also loop through these reference field and get blogs written by that author

Pass through field example

Consider you have a item, and it has one of the field which is either multi list or drop list, now in either of case there can be a business scenario where you want to show detail of those fields along with main rendering item, As i said SXA offers so many option of doing this same thing in so many ways, but most optimum is by using a variant and a pass through field (basically it loop through that field and runs through all those item and get those field to display)

In my case, i wanted to show on my blog detail page, i wanted to show the detail of author who wrote that blog


 Here as you can see my blog item has author drop list, and following how you can use it using a variant


and following is the output (of course use case will differ from person to person, but that is an example)

 


Similarly, Variant also support loading of preexisting components into existing HTML structure, by using "component" field, you can give any rendering and it will be rendered at the exact location in your mark up which you have created in your variant.

You can easily write an article only on how to use variants effectively, but it's not the scope today so i will not get into it, but variant can give you so much and control over things, i would strongly recommend individuals to try to see how many options do variants offer for their individual needs.

NOTE: It is always a good practice to select thumbnail for your variant, so content authors can easily see which variant is for which purpose from the image and they can select accordingly, otherwise it will only show names and it is hard for them to decide which one to select.

Scriban Template  

One of the another powerful feature of SXA is Scriban, They can be used as an "Additional renderers" of fields or tags or even sections

scribans have lot to offer, and you can display additional fields using template syntax provided by SXA

Clone component

Cloning will help when we do not have control over OOTB view either using variant or any other way, so for example if existing OOTB component has 3 fields in its template, title, description and CTA, but your need you want one more image, two more CTA and one more description field, in this type of scenario you can also create a rendering variant and inherit it from your new template, but rendering variant are not for those purposes, in these types of scenario, we should always clone the component and have our fresh version of that component created from OOTB component, now because its totally a new component, we can change the template the way we want and use it as we want as its our own component, remember the rendering pipeline etc. will still remain same, but we will have more flexibility over additional fields.(again you can combine power of variant along with this)

Custom Component

When we want total control over business logic and view, consider reading from third party API and trying to create a view from that, we will need totally custom view

Consider a example where you want to read from a weather API and show the weather of selected cities, here cities can be passed from Sitecore but we will need to make and API call to RSS feed or on some end point to get the weather data, this is where custom component will come into picture, where it will be totally custom view, model, controller, and even repository.

As you can see SXA has so many different ways to offer same thing, so no way is right way or no way is wrong way, it all depends on what is the business need and how can you achieve most efficiently

I am planning to write some of the real tricks or rather smarter ways which we used different scenarios, may be will cover that in the next post

Hope this was helpful.

Thanks for today 

Comments

Post a Comment

Popular posts from this blog

Why SitecoreAI - Getting into the shoes of the customer how to select right CMS

Hi Team, Lately, I have been talking to lot of our customers / potential customers and having pre-sales demos where one question always comes is "Why Sitecore" ?  Now this question can be for any product which is out for sell. And as a technician I always get into product technical features, but at the same time as a pre-sales guy, it also makes me think, surely all competitive products have same features, so definitely answer to this is not in the technicalities.  If you step back and think, we are also a customer in our daily life and buy lot of things, what is that process we go through? When we buy, how can your customer decide if this is a right fit for you or not, why we select A over B? Is it price? is it service? Is it a brand? Is it about features? Is it about brand loyalty?  When it is a technical product, I am sure it cannot start with the technicalities of the product or selecting product itself, 100% not, I feel decision is always business strategy first and ...

Hell of sitecore aliases pipeline breaking the site with 500 error

Hello Friends, I belive this blog post is very important for everyone because, It has some very serious effect on working of your headless website, i will share my experience what we faced and how we resolved it Issue we started facing Our site started giving "Key cannot be null or empty" with YSOD like following  Side affect Because of this 500 error, Our site pages were showing 500 custom error page intermittently and our MAU (Monthly Active User) drop rate increased. Sitecore KB There is already Sitecore KB article talking about this error but the patch which is provided on this link is confusing as well as very huge and it could bring other issues along with it as that upgrade patch also has lot of other things too which i did not want to introduce in our stable CMS. Known Issues - Retrieving the child items of resource items is not thread-safe Observation Though the surfaced exception was looking similar and giving same error and behavior given on this article, We looked...

Zero to Hero - A real life RCA of exact issue in Sitecore Managed Cloud environment

Hello All, The purpose of today's post is to share a real life burning and escalated scenario which was new to me and how did I approach it and how big the escalations were and what was the outcome Sitecore's goodwill was at stack not because Sitecore is not capable of handling it but just because our environment was Sitecore Managed Cloud, and any issue that comes if its infra, back end code, front end code will be first pointed as Sitecore issue and that is where our consultancy and experience will play a role to prove that it is not Sitecore issue.  Issue we faced Out of the blue our site started giving "504 Gateway Time-out", and it was reported that almost everyone is getting this error, but when we used to browse the site, everything looked good and never 504. 504 Gateway Time-out error tells that, That the request went to Content Delivery servers of Sitecore from gateway, but gateway did not get response in time from those CDs and hence it gave time out error. ...