Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David 27 posts 127 karma points
    Mar 16, 2020 @ 14:10
    David
    0

    Grouping by Date when iterating through a list

    Hi all, I have a list of child items that i want to iterate through and group by date. However I'm not sure how to compare the dates of the current and next item in the list to do so. Here's what I have so far:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
    var pubsNode = Umbraco.TypedContentAtRoot().First().Children("publicationRecordListing").First();
      }
    

    <h2 class="beta push__bottom">Publications</h2>
    @{
        if (pubsNode != null)
        {
            foreach (var item in pubsNode.Children.OrderByDescending(n => n.GetPropertyValue<DateTime>("publicationDate")).Take(3))
            {
                if (!item.GetPropertyValue<bool>("hideFromListings"))
                {
                <a href=">
                    <section class="category-item">
                        <h1 class="category-item__title">@item.Name</h1>
                        <div class="category-item__summary">@(item.GetPropertyValue<DateTime>("publicationDate").ToString("dd MMMM yyyy"))</div>
    
                    </section>
                </a>
                }
            }
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft