0

I want to map child items which come from a parent data source and I gave the parent datasource as the datasource for the rendering.

This is my Datasource in my rendering DataSource Image

This is my list of child items under my datasource

Child Content

Now I want to map the child items using Glassmapper. How to do that?

Here is my Controller code

enter image description here

Here are my Models

enter image description here

enter image description here

1
  • Can you please share screenshot of your view file code Jul 20, 2022 at 11:53

2 Answers 2

1

The simplest method to retrieve the child items is to use the children attribute:

public class Home
{
    public virtual IEnumerable<Child> Children { get; set; }
}

If all children are one type then you can use:

public class Home
{
    [SitecoreChildren]
    public virtual IEnumerable<Product> Products { get; set; }

    [SitecoreChildren]
    public virtual IEnumerable<News> News { get; set; }
}

Product and News are example of types of children.

2
  • Its not working Himmat
    – Raviraja
    Jul 19, 2022 at 10:46
  • Can someone please share a demo code?
    – Raviraja
    Jul 22, 2022 at 5:33
1

I used this code and it is working for me. Please try this.

This is the main class

[SitecoreType(TemplateId = "youritemtemplate", EnforceTemplate = SitecoreEnforceTemplate.Template)]
public class FilterGroup : GlassBase
{
    [SitecoreField("Name")]
    public virtual string Name { get; set; }

    [SitecoreChildren (InferType = true, IsLazy = false)]
    public virtual IEnumerable<FilterOption> FilterOptions { get; set; }
}

This is child class

[SitecoreType(TemplateId = "youritemtemplate", EnforceTemplate = SitecoreEnforceTemplate.Template)]
public class FilterOption : GlassBase
{
    [SitecoreField("Name")]
    public virtual string Name { get; set; }
}

Hope this will work for you.

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.