1

I'm trying to créate a carousel and i have a PlayerCard model that will work as a slide for my carousel. Then i have an interface ICarousel that has the main fields of the carousel and a PlayersCarousel that will implement the interface.

Something like this:

[SitecoreType(TemplateId = "{5B0B5442-D005-49A1-84DD-56788DCCD315}")]
    public class PlayersCarousel : SitecoreGlassMap<ICarouselV2>
    {
        public virtual IEnumerable<PlayerCard> Items { get; set; }
        public override void Configure()
        {
            Map(x=> x.AutoMap());
        }
    }

    public interface ICarouselV2
    {
        string BackgroundColor { get; set; }
        bool IsArrowHidden { get; set; }
        bool IsBulletHidden { get; set; }
        int AnimationTime { get; set; }
        int ItemsPerSlide { get; set; }
    }

Now, the PlayerCard is an ítem on sitecore that is mapped to a view rendering (named Player Card). The razor view PlayersCarousel.cshtml will have this:

@inherits GlassView<PlayersCarousel>
@using ConexioFC.Models

@*------ I don't know what goes here--------*@

My question is how do i map the Ítems property of PlayersCarousel with the view rendering Player Card?

I'm using Glass.Mapper v4 with all this.

1 Answer 1

2

I am assuming that you are looking for a way of mapping sub-items of a particular parent in the tree. You can use Sitecore query for mapping your Items property:

[SitecoreQuery("./*[@@templateid='tid']", IsRelative = true)]
public virtual IEnumerable<PlayerCard> Items { get; set; }

Please, check this Glass tutorial for more details: http://www.glass.lu/Blog/GettingChildItems

Edit

You can iterate though your items in the view like that:

<div class="my-component">
    @foreach(var item in Model.Items)
    {  
        <div class="component-item-body">
            <p>@item.Text</p>
        </div>
    }
</div>
5
  • I know how to map child items but i don't know how to use those child items on the parent razor view and represent the child view render on the razor view
    – Phoenix_uy
    Commented Feb 11, 2017 at 14:01
  • 1
    So model.Items does not give you a iEnumerable list?
    – RReilley
    Commented Feb 11, 2017 at 15:02
  • Yes... Model.Items does give a IEnumerable list, what i'm asking is how to write the code on the cshtml razor view to output the corresponding view rendering of each item of the Model.Items list
    – Phoenix_uy
    Commented Feb 13, 2017 at 12:30
  • I know that i can iterate over the Items... but how do i associate the viewrender on sitecore with each item...? that's my main question.
    – Phoenix_uy
    Commented Feb 13, 2017 at 14:55
  • @Phoenix_uy can you follow this tutorial on how to set up a controller rendering? joe-stevens.com/2014/09/07/… Commented Feb 13, 2017 at 16:00

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.