Forked from vitaliitylyk/DescendantsTreeRenderingContentsResolver.cs
Created
June 20, 2019 12:43
-
-
Save isaadansari/c448c057c40c4cd712c20ac369da18f4 to your computer and use it in GitHub Desktop.
A custom Sitecore JSS rendering contents resolver, which serializes items into a tree-like JSON structure. More information at https://blog.vitaliitylyk.com/jss-and-arbitrary-item-hierarchies/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json.Linq; | |
using Sitecore.Data.Items; | |
using Sitecore.LayoutService.Configuration; | |
namespace VitaliiTylyk.JavascriptServices.RenderingContentsResolvers | |
{ | |
/// <summary> | |
/// Builds a tree-like structure of datasource item's descendants | |
/// </summary> | |
public class DescendantsTreeRenderingContentsResolver : Sitecore.LayoutService.ItemRendering.ContentsResolvers.RenderingContentsResolver | |
{ | |
protected override JObject ProcessItem(Item item, IRenderingConfiguration renderingConfig) | |
{ | |
var jObject = base.ProcessItem(item, renderingConfig); | |
if (item.Children.Count == 0) | |
{ | |
return jObject; | |
} | |
jObject["items"] = ProcessItems(item.Children, renderingConfig); | |
return jObject; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment