Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Apr 03, 2017 @ 13:58
    Claushingebjerg
    0

    listing child nodes from multiple sources

    Im sure i have done this before, but im lost as how to do it now. So a bit of help would be appreciated :)

    I have 2 nodes, and want to list the children from both in one joined list.

            @{ 
            var kunstroot = @Umbraco.TypedContent(2526).Children.Where("Visible");
            var kunstrootarkiv = @Umbraco.TypedContent(4457).Children.Where("Visible");
        }
    ....
    
    foreach (var item in kunstroot) 
    {                           
    <p>loop</p>
    }
    

    I need help to merge the to vars, so i can do the foreach. Thanks

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 03, 2017 @ 14:02
    Alex Skrypnyk
    100

    Hi Claushingebjerg

    Try these lines:

    var kunstroot = Umbraco.TypedContent(2526).Children.Where("Visible").ToList();
    var kunstrootarkiv = Umbraco.TypedContent(4457).Children.Where("Visible").ToList();
    
    var mergedList = kunstroot.Concat(kunstrootarkiv);
    

    Thanks,

    Alex

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Apr 03, 2017 @ 14:10
    Dan Diplo
    2

    Probably simplest way would be to convert to a list and then use AddRange like so:

    var kunstroot = Umbraco.TypedContent(2526).Children.Where("Visible").ToList();
    var kunstrootarkiv = Umbraco.TypedContent(4457).Children.Where("Visible");
    kunstroot.AddRange(kunstrootarkiv);
    
  • Claushingebjerg 939 posts 2574 karma points
    Apr 03, 2017 @ 14:15
    Claushingebjerg
    1

    Thanks guys, works like a charm :)

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Apr 03, 2017 @ 14:17
    Alex Skrypnyk
    0

    You are welcome!!!! Glad to help.

Please Sign in or register to post replies

Write your reply to:

Draft