Create Custom Rendering Contents Resolver for Sitecore Headless Application

Use case: We have a requirement of Country Language selector component which will display country name , language and flag information. 


Why we need here Custom Rendering Contents Resolver?

The requirement looks pretty simple except one point i.e. Country name and flag data which are  available in .Net Culture Info class (System.Globalization.CultureInfo). Hence we need to write the custom resolver here to extract the Country specific data from CultureInfo class.

Solution: Here are the steps to create the Custom Rendering Contents Resolver - 

  • Should have Site level languages list available somewhere in the content tree for this component and the applicable languages can be selected from this list.

  • Define your custom resolver under  /sitecore/system/Modules/Layout Service

  • Provide the Assembly information in the Type field for you Custom Contents Resolver.

  • Now create one JSON rendering for this and make sure to use the same Resolver we just created above.


Coding part - 

  • Create one class which inherits RenderingContentsResolver class.

  • Override the ResolveContents method. In this method we'll access the Datasource item and make a call to the function which will actually extract the country information. The highlighted line does this job.

  • Write the custom logic in GetLanguageInfo methd to extract the Country information which are required.

  • Layout Service response of this resolver call - 


Thanks for reading this article!

S Kumar

Comments

Popular posts from this blog

Setup Sitecore XM Cloud Dev Environment using Docker

Sitecore Content Hub - Triggers, Actions and Scripts

All Blog Posts - 2023