Posts

Showing posts from June, 2023

Fetch Site Settings in Layout Service using GetLayoutServiceContext Pipeline

Image
We can add our own data to the context object at any time by extending the getLayoutServiceContextpipeline provided by the Layout Service. In my previous blog , I discussed about GraphQL approach to fetch the Site Settings item which is absolutely required in many cases where Site specific settings needs to be available across the renderings. As we already know i n Sitecore headless architecture these settings item won't be exposed to Layout service by default since this is not a part of any renderings but many renderings depend on these settings value. So we have the  LayoutServiceContextpipeline provided by the Layout Service to accomplish this task. Let's do it using GetLayoutServiceContext pipeline.   Assumption  - Visual Studio Solution setup is already done based on the project needs or using  getting started  template. Use case - Let's consider this site structure and suppose we have to fetch the highlighted Site Settings using  GetLayoutServiceContext pipeline . Op

GraphQL query to fetch Site Settings item in Next JS application.

Image
Use Case - This is a very common requirement where we need to keep some Site specific settings in Sitecore content tree underneath of Site root item.  In Sitecore headless architecture these settings item won't be exposed to Layout service by default since this is not a part of any renderings but many renderings depend on these settings value. Solution -  We can expose the settings item to the front end application either by extending the  JssGetLayoutServiceContext  pipeline  or directly through the GraphQL query from the front end application which is the easiest way of implementing it.  Here we will cover the GraphQL approach and will discuss the other approaches in the upcoming blog. Let's consider this site structure and suppose we have to fetch the highlighted Site Settings using GraphQL. GraphQL Query -  query SearchQuery( $pageSize: Int = 2 $language: String = "en" $rootpath: String = "{F4C787E3-FE05-4211-BD62-1FA238E50A57}") { pageOne: sea

Create Custom Rendering Contents Resolver for Sitecore Headless Application

Image
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 cl