orchardcmsorchardcms-1.9

How do I maintain the correct order of widgets in an overridden Zone template?


I overrode the Zone-AsideSecond template like so to add some classes to the tag:

@{
    Model.Id = "zone-aside-second";
    var tag = Tag(Model, "section");
    tag.Attributes.Add("data-spy", "affix");
    tag.Attributes.Add("data-offset-top", "300");
}
@tag.StartElement
@DisplayChildren(Model)
@tag.EndElement

But now the widgets in the zone don't respect their Position anymore and are just rendered in the order they were created. I tried fixing it like this:

Model.Items = ((IEnumerable<dynamic>)Model.Items).OrderBy(c => Int32.Parse(c.ContentItem.WidgetPart.Position));

But that didn't seem to make a difference.


Solution

  • Orchard has an method to order widgets in the right way, you can use it as following:

    @foreach (var item in Orchard.Core.Shapes.CoreShapes.Order(Model)) {
        @Display(item)
    }