Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 18, 2013 @ 13:44
    Fuji Kusaka
    0

    CurrentModel not displaying Child of Current

    Hi everyone,

     

    Am having some weird issues here in a sub nav where i need to display only the child of the current Node.

    However its showing all the child nodes of the current page but under all of the other parent as well instead of the actual current node.

    Can someone have a look at the code here. 

      <li><a @style @link>@i.Name</a>
    @if(i.ChildrenAsList.Where(x=>x.GetProperty("umbracoNaviHide").Value !="1" && x.NodeTypeAlias == "LLL" || x.NodeTypeAlias == "LC").Count()>0){
    <ul class="sous-menu clearfix">
      @foreach(dynamic node in i.ChildrenAsList){
    <li class="@node.Name.Replace(" ", "-").ToLower()"><a href="@node.Url"> @node.Name</a>
    @if(CurrentModel.Children.Where(x=>x.GetProperty("umbracoNaviHide").Value !="1" && x.NodeTypeAlias == "LP").Count()>0){
     
      foreach(var sub in CurrentModel.Children){
      @sub.Name
    }
    </li>   }
      </ul>
    }
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 19, 2013 @ 19:53
    Jeavon Leopold
    0

    Hi Fuji,

    Obviously I don't know what "i" is from the snippet so I have assumed it's the current page, so give this a try:

    @{
        var i = CurrentModel;     
    }
    
    @{
        var myCollection = i.Children.Where(x => x.Visible && x.NodeTypeAlias == "LLL" && x.NodeTypeAlias == "LC");
        if (myCollection.Any())
        {
            <ul class="sous-menu clearfix">
                @foreach (var node in myCollection)
                {
                    <li class="@node.Name.Replace(" ", "-").ToLower()"><a href="@node.Url"> @node.Name</a>
                        @{
                            var mySubCollection = node.Children.Where(x => x.Visible && x.NodeTypeAlias == "LP");
                            if (mySubCollection.Any())
                            {
                                <ul>
                                    @foreach (var sub in node.Children)
                                    {
                                        <li>@sub.Name</li>
                                    }
                                </ul>
                            }
                        }
                    </li>
                }    
            </ul>
        }
    }
    

    Jeavon

  • Fuji Kusaka 2203 posts 4220 karma points
    Dec 20, 2013 @ 04:02
    Fuji Kusaka
    100

    Hi Jeavon, 

    That kind of weird i did remember deleting this threat cuz i kind of made a mistake myself on the navigation!.

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 20, 2013 @ 08:24
    Jeavon Leopold
    1

    Ah well, maybe you can find some useful bits in the above like x.Visible and .Any()

Please Sign in or register to post replies

Write your reply to:

Draft