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
    Jun 21, 2014 @ 15:32
    Fuji Kusaka
    0

    Displaying child node if currentNode has child

    Hi Guys,

    I kind of lost my way here. I need to display sub nodes when current node only has any child node.

    Here is how i have it structured

    Node 1
    Node 2 
    Node 3
    -- SubNode 1
    -- SubNode 2

    So only when on Node 3 page content that i will  display the subContent. Here is how my code looks like

    @foreach(var c in pages.Where(x=>x.GetPropertyValue("umbracoNaviHide").ToString() !="1")){
    
        <li><a href="@c.Url">@Html.Raw(altSubTitle)</a></li>
            if(CurrentModel.Children.Count() > 0){
                    @Model.Name
            }
        }

    Weird i cant seem to remember how to achieve this here. Anyone please? 

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 21, 2014 @ 15:54
    Jeavon Leopold
    0

    I'm not totally understanding what your doing but maybe something like:

        if(pages.Id == CurrentModel.Id && CurrentModel.Children.Count() > 0){
                @Model.Name
        }
    }
    
  • Fuji Kusaka 2203 posts 4220 karma points
    Jun 21, 2014 @ 16:12
    Fuji Kusaka
    0

    Hi Jeavon,

    Basically i wanted to display the subNode only if am on the Node 3. So whenever i click on Node 3 i get the sub nodes.

    I did try this but didnt worked

    if(c.Id == Model.Id && c.ChildrenAsList.Where(x=>x.GetProperty("umbracoNaviHide").Value !="1" && x.NodeTypeAlias == "AddSubPage").Count() > 0){

    }

    Instead i managed doing it in css, only displaying the UL when on the current Node 3 or any sub node

    if(c.ChildrenAsList.Where(x=>x.NodeTypeAlias == "DocType").Count() > 0){
        <ul class="sub-navi @Library.If((c.IsAncestorOrSelf(Model)), "subNaviAct", "")">                          @foreach(var page in c.ChildrenAsList.Where(x=>x.NodeTypeAlias == "docType")){
                string active = (page.IsAncestorOrSelf(@Model)) ? "class=current" : "";
                    <li @active><a href="@page.Url">@page.Name</a></li>
                    }
        </ul>
    }
  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 21, 2014 @ 17:25
    Jeavon Leopold
    0

    Hi Fuji

    Ok, so does Node 3 have a special doc type or should we check its Name?

    Jeavon

  • Fuji Kusaka 2203 posts 4220 karma points
    Jun 21, 2014 @ 19:34
    Fuji Kusaka
    0

    No same all of them have the same docType but turns out it stopped working. I need to figure out something else. On a certain level it stopped

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 21, 2014 @ 21:20
    Jeavon Leopold
    0

    Ok, I need to get this straight :-)

    Node structure:

    Node 1
    -- SubNode 1
    -- SubNode 2
    Node 2 
    -- SubNode 3
    -- SubNode 4
    Node 3
    -- SubNode 5
    -- SubNode 6
    

    When rendering Node 3, SubNode 5 and SubNode 6, you want output like

    Node 1
    Node 2 
    Node 3
    -- SubNode 5
    -- SubNode 6
    

    When rendering Node 2, SubNode 3 and SubNode 4, you want output like

    Node 1
    Node 2 
    -- SubNode 3
    -- SubNode 4
    Node 3
    

    Have I got it right?

  • Fuji Kusaka 2203 posts 4220 karma points
    Jun 22, 2014 @ 16:40
    Fuji Kusaka
    0

    Hmmmm yes exactly, 

    Node 1 
    Node 2
    Node 3 - Active Displaying the sub Node 3-4
    -- Sub Node 1
    -- Sub Node 2
    Node 4

    And when under Sub Node 1

    Still displaying 
    Node 1
    Node 2
    Node 3 -- 
    -- Sub Node 1 Active
    -- Sub Node 2
    Node 4 

    And when under Node 1

    Node 1 -- Active
    Node 2
    Node 3
    Node 4
  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jun 23, 2014 @ 18:58
    Jeavon Leopold
    0

    Assuming you are stuck with DynamicNode rather the super fast IPublishedContent. how about something like this:

    @{
        var home = CurrentModel.AncestorOrSelf(1).Children;
        <ul>
            @foreach (var page in home)
            {
                var selectedItemState = page.DescendantsOrSelf().Any(x => x.Id == Current.Id);
                <li class="@(selectedItemState ? "active" : null)">
                    @page.Name
                    @if (selectedItemState && page.Children.Any())
                    {
                        <ul>
                            @foreach (var childPage in page.Children)
                            {
                                var selectedChildItemState = childPage.DescendantsOrSelf().Any(x => x.Id == Current.Id);
                                <li class="@(selectedChildItemState ? "active" : null)">@childPage.Name</li>
                            }
                        </ul>
                    }
            </li>
            }
        </ul>
    }
    
  • 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