Copied to clipboard

Flag this post as spam?

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


  • Marianne Larsen 22 posts 94 karma points
    Nov 03, 2014 @ 08:21
    Marianne Larsen
    0

    Render child-items in different partial views according to doc type

    Hi

    I'm building a website where i need to load several child-items in different partial views and i need it to be possible to change the order of the child-items. Is there any "best pratices" for that?

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Nov 03, 2014 @ 08:30
    Dennis Aaen
    0

    Hi Marianne and welcome to our, 

    You can use the OrderBy in you foreach loop. The OrderBy orders a collection by a field name.

    Take a look at these cheat sheets, I know it says version 6, but you can use it for version 7 too. There are both cheat sheets, for dynamic version of Razor and for the strongly typed version. http://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets

    Here are an exaple on how it could looks like where it sort on the name of the nodes:

    <ul>
        @* OrderBy() takes the property to sort by *@
        @foreach (var page in CurrentPage.Children.Where("Visible").OrderBy("Name"))
        {
            <li><a href="@page.Url">@page.Name</a></li>
        }
    </ul>

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft