Hey guys,
I’m having a bit of trouble trying to order some results from a for loop. I’m not very good with razor, so getting the syntax right is killing my brain off! I’m not sure if I need to be looking into the .Where expression or the for loop itself.
I’d like the months to be outputted by publishDate Descending.
@helper RenderMonthChildren(umbraco.MacroEngines.DynamicNode month)
{
var posts = month.Children.Where(c => c.Visible && c.NodeTypeAlias == "BlogEntry");
if(posts.Any())
{
foreach(var post in posts)
{
<div class="blog-post-summary">
<h3><a href="@post.Url">@post.GetPropertyValue("heading")</a></h3>
<p class="blog-date"><em>@DateTime.Parse(post.GetPropertyValue("publishDate")).ToString("ddd, dd MMMM yyyy")</em></p>
<p>@post.GetPropertyValue("summary")<br /><br /></p>
<p class="blog-read-more"><a href="@post.Url">Read more</a></p>
</div>
}
}
}
Any help would be much appreciated!
Thanks,
Tom
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/74732-orderby-for-loop