Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 886 posts 2415 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 5908 posts 22603 karma points MVP 4x 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 1505 posts 5911 karma points MVP 4x 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 886 posts 2415 karma points
    Apr 03, 2017 @ 14:15
    Claushingebjerg
    1

    Thanks guys, works like a charm :)

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Apr 03, 2017 @ 14:17
    Alex Skrypnyk
    0

    You are welcome!!!! Glad to help.

  • 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