Sunday, February 27, 2022

Sitecore Layout Demo

 

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 4:

·         create new rendering in Sitecore JSS







Step 5:

·         Add rendering to the page



Step 6:

·         Check the layout service result

https://sc102sc.dev.local/sitecore/api/layout/render/jss?item={49D28007-AFAF-49A7-B6AE-08E05FBAEB76}&sc_apikey={81E7F129-B5DA-4EC7-8C85-C5B2FE3FA3A1}

Before

After

Step 7:

·           Check the page in your site.


Step 8:

·         Create new component in JSS app


·         This is Sitecore definition item





·         Now I added the fields which are available in templates,

·         This is components definition item.



·         We have to loop all the event list here by help of react team.

No comments:

Post a Comment

Steps to follow when using a PowerShell script to modify the goals in Sitecore

I have previously utilized PowerShell for item creation, modification, deletion, and presentation details in Sitecore.   Ø Recently, I attem...