Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save anastasiya29/ae38aa3cd620b1b00b2a1d80b68c2e61 to your computer and use it in GitHub Desktop.
Save anastasiya29/ae38aa3cd620b1b00b2a1d80b68c2e61 to your computer and use it in GitHub Desktop.
Custom Sitecore JSS Descendants resolver
/// <summary>
/// Builds a tree-like structure of datasource item's descendants
/// </summary>
/// <seealso cref="Sitecore.LayoutService.ItemRendering.ContentsResolvers.RenderingContentsResolver" />
public class DescendantsRenderingContentsResolver : 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