Copied to clipboard

Flag this post as spam?

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


  • dominik 711 posts 733 karma points
    Aug 31, 2012 @ 13:13
    dominik
    0

    help for loop through child items

    Hello,

    I have the following structure in content tree:

    en
    - footer
    - - news (document type "News")
    - - - news item 1  (document type "NewsItem") 
    - - - news item 2 (document type "NewsItem") 

    Now i want to loop through all news items from a hight located page 

    I tried the following:

    foreach (dynamic item in Model.DescendantsOrSelf().News.Children) {

    But this does not work 

  • Funka! 398 posts 660 karma points
    Aug 31, 2012 @ 19:15
    Funka!
    0

    I have this same structure in one of my sites, I used the lovely XPath method of the model node to very easily do what you ask.

    For a bonus I also am showing here how to order them by some additional date property we have on our news items (in case natural/sorted order is not desired)...

    @foreach (varitem in @Model.XPath(@".//NewsItem").OrderBy("displayDate desc"))

    Best of luck to you!

  • Funka! 398 posts 660 karma points
    Aug 31, 2012 @ 19:16
    Funka!
    0

    Sorry, my post above of course should say var item, with a space, not varitem!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies