Content Resolver in Sitecore JSS
Sitecore Headless provides six rendering contents resolvers
Path:Â /sitecore/system/Modules/Layout Service/Rendering Contents Resolvers.
Content Resolver types & Definitions
Context Item Children Resolver:Â resolves/serializes the children of the context item
Context Item Resolver:Â resolves/serializes the context item
Datasource Item Children Resolver: resolves/serializes the children of the rendering’s datasource item
Datasource Resolver: resolves/serializes the rendering’s datasource item
Folder Filter Resolver: resolves items of Folder template type. The Template ID is specified in the Item Selector Query field of the resolver item in Sitecore.
Sitecore Forms Resolver: resolver specific to form items.
The class should inherit the Sitecore.LayoutService.ItemRendering.ContentsResolvers.RenderingContentsResolverand must override ResolveContents method of the base class.
Content resolver class file -- code
Namespace and Imports:
Â
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Sitecore;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.LayoutService.Configuration;
using Sitecore.LayoutService.ItemRendering.ContentsResolvers;
using Sitecore.Mvc.Presentation;
using Newtonsoft.Json.Linq;
Â
namespace content_resolver.Controller
{
CustomRenderingContentsResolver Class:
    public class CustomRenderingContentsResolver : RenderingContentsResolver
{
Â
       Â
ResolveContents Method Override:
Â
public override object ResolveContents(Rendering rendering, IRenderingConfiguration renderingConfig)
        {
            //check if the parameters are not null
            Assert.ArgumentNotNull(rendering, nameof(rendering));
            Assert.ArgumentNotNull(renderingConfig, nameof(renderingConfig));
Â
            //get the datasource item
            Item datasourceItem = this.GetContextItem(rendering, renderingConfig);
Â
            //return null object if the datasourceItem is null
            if (datasourceItem == null)
                return null;
Â
            //initialize the JSON object to be returned with the datasourceItem details
            JObject jobject = ProcessItem(datasourceItem, rendering, renderingConfig);
Â
            //get the children of the datasourceItem
            IEnumerable<Item> items = GetItems(datasourceItem);
            List<Item> itemList = items != null ? items.ToList() : null;
Â
            //return the JSON object if children do not exist
            if (itemList == null || itemList.Count == 0)
                return jobject;
Â
            //add children item details to the JSON object and return the object
            jobject["items"] = ProcessItems(itemList, rendering, renderingConfig);
            return jobject;
        }
    }
}
Creating layout service file - CustomRenderingContentsResolver
Create a new folder of /sitecore/templates/System/Layout/Layout Service/Rendering Contents Resolvers Folder type inside Rendering Contents Resolvers using the insert options.
Create the custom content resolver, again, using the insert options.Â
Created New component in Banner section
l Postmen url send then display the json file .
l Postman url send then display the json file .