Step 1:
· Create template and datasource folder
·
Create template folder which keeps
the new template items.
Step 2:
·
Write a code for ContentResolver
public class EventsListResolver : Sitecore.LayoutService.ItemRendering.ContentsResolvers.RenderingContentsResolver
{
private List<Item> items = new List<Item>();
public override object ResolveContents(Sitecore.Mvc.Presentation.Rendering rendering, IRenderingConfiguration renderingConfig)
{
Assert.ArgumentNotNull(rendering, nameof(rendering));
Assert.ArgumentNotNull(renderingConfig, nameof(renderingConfig));
Item ds = GetContextItem(rendering, renderingConfig);
var recommendedItemsFieldId = Templates.EventRenderingModel.TemplateId;
//if the rendering datasource has curated items
if (ds != null)
{
foreach (Sitecore.Data.Items.Item childItem in ds.Children)
{
items.Add(childItem);
}
}
if (!items.Any())
return null;
JObject jobject = new JObject()
{
["items"] = (JToken)new JArray()
};
List<Item> objList = items != null ? items.ToList() : null;
if (objList == null || objList.Count == 0)
return jobject;
jobject["items"] = ProcessItems(objList, rendering, renderingConfig);
return jobject;
}
private string GetItemUrl(Item item)
{
return Sitecore.Links.LinkManager.GetItemUrl(item);
}
}
Step 3:
·
Create Content Resolver in Sitecore
Step 5:
·
Add rendering to the page
Step 6:
·
Check the layout service result