Copied to clipboard

Flag this post as spam?

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


  • Billy 53 posts 244 karma points c-trib
    Apr 01, 2021 @ 13:43
    Billy
    0

    Order children based on listview settings in front-end

    Hi,

    I was wondering if it is possible to access listview settings of PublishedContent?

    An example:

    Listview settings for news items, that are ordered descending by 'Date' field

    enter image description here

    Printing news items will use 'sortOrder' by default:

    var current = Umbraco.AssignedContentItem; 
    var children = current.Children<ContentModels.NewsDetailPage>();
    foreach (var child in children)
    {
        <div class="news-item">
            @{
                ...
            }
        </div>
    }
    

    It is possible to order these by 'Date'

    @foreach (var child in children.OrderByDescending(x => x.Date))
    {
        <div class="news-item">
            @{
                ...
            }
        </div>
    }
    

    I would like to re-use my @foreach for several other types of pages with children. Each with a different order field setting. So is it possible to access the settings?

    Thanks for any advice.

Please Sign in or register to post replies

Write your reply to:

Draft