Copied to clipboard

Flag this post as spam?

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


  • Jimmy Dan Mortensen 77 posts 197 karma points
    Jun 05, 2019 @ 20:35
    Jimmy Dan Mortensen
    0

    Nested foreach using children from content pickers

    Hi Gurus,

    Can someone help a noob :-)

    I have created some cities, some clubs and some training-centers.

    On each club/trainingcenter I have a contentpicker that points to the city, but how do I show which clubs and centers are present in the current city?

    my current code looks like this:

        @{
            string nodeSel = Model.MapCityNodePicker.ToString();
            string nodeSelClubs = Model.MapClubNodePicker.ToString();
            string nodeSelCenters = Model.MapTrainingCenterNodePicker.ToString();
            string nodeSelDevCenters = Model.MapDevelopmentCenterNodePicker.ToString();
    
            var selection = Umbraco.TypedContent(nodeSel).Children("city")
                        .Where(x => x.IsVisible());
        }
        <ul>
            @foreach (var cityItem in selection)
            {
                var selClubsInCity = Umbraco.TypedContent(nodeSelClubs).Children("clubs").Where(x => x.IsVisible()));       
                <li>
                    @cityItem.Name, Klubber: @nodeSelClubs, Talent: @nodeSelCenters, Udv.centre: @nodeSelDevCenters - @selClubsInCity.Count().ToString()
    
                    <ul>
                        @foreach (var clubsItem in Umbraco.TypedContent(nodeSelClubs).Children())
                        {
                            <li>@clubsItem.Name, @clubsItem.cityPicker - @cityItem.id</li>
                        }
                    </ul>
                </li>
            }
        </ul>
    }
    

    My question is how do I only get the clubs that has the "current" club selected? I'm guessing I have to write a ".Where(x => ..." but I can't seem to find the correct syntax

    I hope someone can help me and make it all more clear :-)

    /Jimmy Dan Mortensen

  • Lewis Logan 21 posts 132 karma points
    Jun 11, 2019 @ 16:05
    Lewis Logan
    0

    Hi Jimmy,

    Are you looking for all the clubs that are a child under the current city? Because wouldn't that be similar to how you've gathered the selection of cities?

    It be something along the lines of:

    @foreach (var cityItem in selection)
    {
       var clubs = cityItem.Children("clubs").Where(x => x.IsVisible());
        ...
    }
    

    Then get the information you need. Please let me know if this has helped.

    Kind Regards, Lewis

  • Jimmy Dan Mortensen 77 posts 197 karma points
    Jun 11, 2019 @ 16:09
    Jimmy Dan Mortensen
    0

    Hi Lewis,

    They are not children to cityItem, but I have almost gotten it to work. I'm just having issues with how to use the x.GetPropertyValue == nodeSelClubs.

    It's something really stupid, but I'll post it here when I get it working.

    /Jimmy

Please Sign in or register to post replies

Write your reply to:

Draft