Copied to clipboard

Flag this post as spam?

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


  • Michael Findley 6 posts 87 karma points
    Feb 16, 2018 @ 21:03
    Michael Findley
    0

    Umbraco V7 - Razor - Submenu issues

    I am pretty new to umbraco so bare with me. I am trying to get my submenu to function correctly. My code below is the whole menu, but my submenu part pulls all nodes from lvl2. So not just the nodes under About or under services for example.

    Trying to just get a main navigation with a submenu. Thank for the assistance here. Again sorry still pretty new with umbraco.

    <div id="desktop-nav">
                    <ul id="d-list">
                        <li class="d-parent" ng-repeat="item in navItems">
                            @{
                                var selection = Model.Content.Site().Children().Where(x => x.IsVisible());
                            }
                            <ul>
                                @foreach(var item in selection){
                                   <li class="d-parent" ng-repeat="item in navItems">
                                        <div class="d-name-wrapper">
                                            <h3>@item.Name</h3>
                                        </div>
    
                                                <!-- Sub Navigation Start -->
                                        <ul class="d-children under" ng-if="item.children">
                                            @foreach(var subitem in Model.Content.DescendantsOrSelf().Where("Visible").Where("level > 2"))
                                            {
                                                <li ng-repeat="child in item.children"><a href="@subitem.Url">@subitem.Name</a></li>
                                            }
                                        </ul>
                                    </li>
                                }
                            </ul>
                        </li>
                  </ul><!-- end of d-list -->
    
                  </div>
    
  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Feb 16, 2018 @ 22:56
    Marc Goodson
    100

    HI Michael

    I think you just need to tweak your inner foreach loop, so you are iterating over the 'children' of the current item in the outer for each loop...

    try replacing:

     @foreach(var subitem in Model.Content.DescendantsOrSelf().Where("Visible").Where("level > 2"))
                                            {
                                                <li ng-repeat="child in item.children"><a href="@subitem.Url">@subitem.Name</a></li>
                                            }
    

    with

     @foreach(var subitem in item.Children.Where("Visible"))
                                            {
                                                <li ng-repeat="child in item.children"><a href="@subitem.Url">@subitem.Name</a></li>
                                            }
    

    that should write out only the lv2 children of each lv1 item, underneath that particular lv1 item...

    unless of totally misunderstood what you are trying to do!

    regards

    Marc

  • Michael Findley 6 posts 87 karma points
    Feb 19, 2018 @ 15:06
    Michael Findley
    1

    @marc, thank you so much bud. That is all it was. WOW just needed that extra set of eyes and expertise. THANK YOU. We can close this ticket.

Please Sign in or register to post replies

Write your reply to:

Draft