Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save joostbroekhuizen/91f217b1724628f43ff4b021b2b41f60 to your computer and use it in GitHub Desktop.
Save joostbroekhuizen/91f217b1724628f43ff4b021b2b41f60 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