• Not Answered

Implementing a Carousel with Glass Mapper for Sitecore

I am new to Sitecore hence, looking for help from Sitecore enthusiasts.
I am implementing a carousel using Glass Mapper (V8.2)

I have a data source (a simple folder) which has three carousels as child items each of which consists an image, text and multiple links (tree list of navigation links)

This is the model for each carousel:

[SitecoreType(TemplateId = "{B4AF4BE8-A1C4-42E3-A578-9B7B69066B3A}", AutoMap = true)]

public class Carousel
{
[SitecoreField]
public virtual Image CarouselImage { get; set; }

[SitecoreField]
public virtual string CarouselText { get; set; }

[SitecoreChildren(InferType = true)]
public virtual IEnumerable<NavigationItem> CarouselLinks { get; set; }

}

[SitecoreType(TemplateId = "{E7D13789-22BF-491D-9CF4-D8C2A2D16724}", AutoMap = true)]
public class NavigationItem
{
[SitecoreField]
public virtual string Title { get; set; }

[SitecoreField(FieldType = SitecoreFieldType.GeneralLink)]
public virtual Link Url { get; set; }
}

This is how my view looks like:


@foreach (var item in Model)
{

@Html.Glass().RenderImage(item, x => x.CarouselImage, isEditable: true)
<br />
@foreach (var link in item.CarouselLinks)
{
@Html.Glass().Editable(link,x=>x.Title)
@Html.Glass().RenderLink(link, x => x.Url, isEditable: true)
}

<br />
@Html.Glass().Editable(item, x => x.CarouselText)


}


I am stuck on implementing the Controller where I could not get the carousel to work.

 


var mvcContext = new MvcContext();

var currentItem = RenderingContext.Current.Rendering.Item;

var list = new List<Carousel>();
if (currentItem.HasChildren)
{
foreach (Item item in currentItem.Children)
{
list.Add(mvcContext.SitecoreService.GetItem<Carousel>(item));
}
}
return View(list);


Your help/suggestions will be highly appreciated.
Thanks

1 Reply

  • Subash,
    Code appears to be correct, so you would need to dig deeper into how you are setting everything up. I would recommend finding a good tutorial and follow it step by step. Sorry, can't spoon feed more then this :)