Copied to clipboard

Flag this post as spam?

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


  • Nico Viergever 20 posts 81 karma points
    May 25, 2015 @ 00:58
    Nico Viergever
    0

    Fanoe starterkit navigation

    I am new to Umbraco and just downloaded the latest version. I is difficult to get up-to-speed because of the lack of documentation. I want to create a site that is split up in several diffent areas. On the top level (level 1) I only want the toplevel of these areas and the pages directly linked to the toplevel, e.g. "Contact Us".

    But as soon as a we are in one of the areas (level 2) I want the menu to show all underlying pages, but only for this area.

     

    What do I do? How to change the code of the Partial View MainNavigation (see below)

     

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{ var home = CurrentPage.Site(); }
    @if (home.Children.Any())
    {
        @* Get the first page in the children *@
        var naviLevel = home.Children.First().Level;
       
        @* Add in level for a CSS hook *@
        <ul class="level-@naviLevel">           
            @* For each child page under the home node *@
            @foreach (var childPage in home.Children)
            {  
                if (childPage.Children.Any())
                {                   
                    <li class="has-child @(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
         @if(childPage.DocumentTypeAlias == "LandingPage")
         {
                         <span>@childPage.Name</span>
          @childPages(childPage.Children)
         } else {
          <a href="@childPage.Url">@childPage.Name</a>
         }
                    </li>
                }
       else
                {
                    <li class="@(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
                        <a href="@childPage.Url">@childPage.Name</a>
                    </li>
                }           
            }
        </ul>
    }
    @helper childPages(dynamic pages)
    {
        @* Ensure that we have a collection of pages *@
        if (pages.Any())
        {
            @* Get the first page in pages and get the level *@
            var naviLevel = pages.First().Level;
           
            @* Add in level for a CSS hook *@
            <ul class="sublevel level-@(naviLevel)">
                @foreach (var page in pages)
                {
                    <li>
                        <a href="@page.Url">@page.Name</a>
                       
                        @* if the current page has any children *@
                        @if (page.Children.Any())
                        {                       
                            @* Call our helper to display the children *@
                            @childPages(page.Children)
                        }
                    </li>
                }
            </ul>
        }
    }
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 25, 2015 @ 11:04
    Dennis Aaen
    0

    Hi Nico,

    If I have understand your question correctly, then I think that this peice of code should at least help you in the right direction.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{ var home = CurrentPage.Site(); }
    
    @if (home.Children.Any())
    {
        @* Get the first page in the children *@
        var naviLevel = home.Children.First().Level;
    
        @* Add in level for a CSS hook *@
        <ul class="level-@naviLevel">            
            @* For each child page under the home node *@
            @foreach (var childPage in home.Children)
            {   
                if (childPage.Children.Any())
                {                    
                    <li class="has-child @(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
                        @if(childPage.DocumentTypeAlias == "LandingPage") 
                        {
                            <a href="@childPage.Url">@childPage.Name</a>
                            @childPages(childPage.Descendants())
                        } else {
                            <a href="@childPage.Url">@childPage.Name</a>
                        }
                    </li>
                } 
                else
                {
                    <li class="@(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
                        <a href="@childPage.Url">@childPage.Name</a>
                    </li>
                }            
            }
        </ul>
    }
    
    @helper childPages(dynamic pages)
    {
        @* Ensure that we have a collection of pages *@
        if (pages.Any())
        {
            @* Get the first page in pages and get the level *@
            var naviLevel = pages.First().Level;
    
            @* Add in level for a CSS hook *@
            <ul class="sublevel level-@(naviLevel)">
                @foreach (var page in pages)
                {
                    <li>
                        <a href="@page.Url">@page.Name</a>
    
                        @* if the current page has any children *@
                        @if (page.Children.Any())
                        {                        
                            @* Call our helper to display the children *@
                            @childPages(page.Descendants())
                        }
                    </li>
                }
            </ul>
        }
    }
    

    You will need to change some CSS so the dropdown only are displaying when you have selected one of the area pages, and not just when you are hovering the menu item.

    If you have further questions to this keep asking, or if I have totally misunderstood what you are trying to archive.

    Hope this helps, /Dennis

  • Nico Viergever 20 posts 81 karma points
    May 25, 2015 @ 12:40
    Nico Viergever
    0

    Thanks Dennis!

    A step forward and I am learning.

    What I wonder now is:

    • At the top level, how do I prevent the menu showing pages under the Landing Pages?
    • When on the level of the Landing Page, how on the menu do I only show the pages under the current Landing Page?

    Looking forward to more of your suggestions!

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 25, 2015 @ 12:58
    Dennis Aaen
    100

    Hi Nico,

    Okay now I am knowing what you are trying to do. With this code below, you first render the landing pages when you are on the homepage. If you are on the learn page, then the menu will display the pages: The starter kit, Basics, Masterclasses

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{ var home = CurrentPage; }
    
    @if (home.Children.Any())
    {
        @* Get the first page in the children *@
        var naviLevel = home.Children.First().Level;
    
        @* Add in level for a CSS hook *@
        <ul class="level-@naviLevel">            
            @* For each child page under the home node *@
            @foreach (var childPage in home.Children)
            {   
                if (childPage.Children.Any())
                {                    
                    <li class="has-child @(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
                        @if(childPage.DocumentTypeAlias == "LandingPage") 
                        {
                            <a href="@childPage.Url">@childPage.Name</a>
                        } else {
                            <a href="@childPage.Url">@childPage.Name</a>
                        }
                    </li>
                } 
                else
                {
                    <li class="@(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
                        <a href="@childPage.Url">@childPage.Name</a>
                    </li>
                }            
            }
        </ul>
    }
    

    Hope this helps,

    /Dennis

  • Nico Viergever 20 posts 81 karma points
    May 25, 2015 @ 13:12
    Nico Viergever
    0

    Dennis,

    This looks exactly like what I was looking for! Thanks a lot.

     

    Cheers

    Nico

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 25, 2015 @ 13:19
    Dennis Aaen
    0

    Hi Nico,

    You´re welcome, happy that I could help you out. You can mark the question as solved by clicking the green tick on the left side of the screen beside the avatar for the post that gives you the right solution.

    By doing this then other people who comes across this post can go directly to the solution which works for you.

    /Dennis

  • Nico Viergever 20 posts 81 karma points
    May 26, 2015 @ 14:24
    Nico Viergever
    0

    I cheered too early.

    When you go to a page under the Landing Page the menu goes empty, when it should keep the same menu as when on the Landing Page. So it does not work correctly.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 26, 2015 @ 19:11
    Dennis Aaen
    0

    Hi Nico,

    I think that this code below should fits your need.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{ var home = CurrentPage.Site(); }
    
    @if (home.Children.Any())
    {
        @* Get the first page in the children *@
        var naviLevel = home.Children.First().Level;
    
        @* Add in level for a CSS hook *@
        <ul class="level-@naviLevel">            
            @* For each child page under the home node *@
            @foreach (var childPage in home.Children)
            {   
                if (childPage.Children.Any())
                {                    
                    <li class="has-child @(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
                        @if(childPage.DocumentTypeAlias == "LandingPage") 
                        {
                            <a href="@childPage.Url">@childPage.Name</a>
    
                        }else{ 
                          <a href="@childPage.Url">@childPage.Name</a>
                        }
                    </li>
                } 
                else
                {
                    <li class="@(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
                        <a href="@childPage.Url">@childPage.Name</a>
                    </li>
                }            
            }
        </ul>
    }
    

    Hope this helps,

    /Dennis

  • Nico Viergever 20 posts 81 karma points
    May 26, 2015 @ 20:07
    Nico Viergever
    0

    Hi Dennis,

    Now I lost my second level.

     

    Nico

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 26, 2015 @ 20:17
    Dennis Aaen
    0

    Hi Nico,

    Could you please post a screenshot on how your menu should look like when you are on different pages. I am not sure what problem was with the last code there you get the child pages for the current page that you are viewing in the browser.

    But you then say When you go to a page under the Landing Page the menu goes empty, did the landing page have any children and if the don´t have children what should then be showing?

    Looking forward to hear from you.

    /Dennis

  • Nico Viergever 20 posts 81 karma points
    May 27, 2015 @ 09:29
    Nico Viergever
    0

    Hi Dennis. This is on a fresh install.

    After your Post that I thought solved my question:

    Looks good so far. No submenus.

    Still good and what I was looking for. But now I click "The starter kit"

    And the menus are gone now.

     

  • Nico Viergever 20 posts 81 karma points
    May 27, 2015 @ 09:32
    Nico Viergever
    0

    Then after your last suggestion:

    When I click the same menu show, no submenus at all anymore.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 27, 2015 @ 10:18
    Dennis Aaen
    0

    Hi Nico, 

    Okay but what was wrong with the old code then, it renders the submenu if the page has any children. It´s that want you want or where did it go wrong then.

    Looking forward to hear from you.

    /Dennis

  • Nico Viergever 20 posts 81 karma points
    May 27, 2015 @ 10:30
    Nico Viergever
    0

    Hi Dennis,

    On the first series of screenshots the menu is gone when on the "The starter kit" page (3rd page). I was looking for the menu shown on the Landing Page "Learn". So the same menu as on the 2nd page of the screenshots in the 1st series.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 27, 2015 @ 10:36
    Dennis Aaen
    0

    Hi Nico 

    Just to ensure that I am right. So when you are on the frontpage you want to see a menu of Learn, Explorer, Extend, Blog and Contact. And when you are on the learn landing page which elements should you then see in the menu, can you point this out.

    Sorry that I don´t get it right.

    /Dennis

  • Nico Viergever 20 posts 81 karma points
    May 27, 2015 @ 10:44
    Nico Viergever
    0

    Hi Dennis,

    Correct about the top level. So the Landing Pages and all othe pages directly under the top level, so in this case "Contact".

    On other levels everything for the current Landing Page. So in this case "The starter kit", "Basics" and "Masterclasses" (and possibly the children).

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 27, 2015 @ 12:04
    Dennis Aaen
    0

    Hi Nico,

    Okay I think I have it now, this code below, should give you what you are after. When you are on the homepage the you will see Learn, Exploerer, Extend, Blog and Contact.

    When you are on the learn item then you will see "The starter kit", "Basics" and "Masterclasses", and their children if they have some.

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{ var home = CurrentPage; }
    
    @if(home.DocumentTypeAlias == "Home") 
    
    { 
    
     var naviLevel = home.Children.First().Level;
    
    
     <ul class="level-@naviLevel">            
    
            @* For each child page under the home node *@
    
            @foreach (var childPage in home.Children)
    
            {   
    
                if (childPage.Children.Any())
    
                {                    
    
                    <li class="has-child @(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
    
                        @if(childPage.DocumentTypeAlias == "LandingPage") 
    
                        {
    
                            <a href="@childPage.Url">@childPage.Name</a>
    
                        } else {
    
                            <a href="@childPage.Url">@childPage.Name</a>
    
                        }
    
                    </li>
    
                } 
    
                else
    
                {
    
                    <li class="@(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
    
                        <a href="@childPage.Url">@childPage.Name</a>
    
                    </li>
    
                } 
    
            }            
    
        </ul>
    
    }
    
    
    
    @if (home.DocumentTypeAlias != "Home")
    
    {
    
        @* Get the first page in the children *@
    
    
    
    
    
        @* Add in level for a CSS hook *@
    
        <ul>            
    
            @* For each child page under the home node *@
    
            @foreach (var childPage in home.Descendants())
    
            {   
    
                if (childPage.Children.Any())
    
                {                    
    
                    <li class="has-child @(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
    
                        @if(childPage.DocumentTypeAlias == "LandingPage") 
    
                        {
    
                            <a href="@childPage.Url">@childPage.Name</a>
    
                        } else {
    
                            <a href="@childPage.Url">@childPage.Name</a>
    
                        }
    
                    </li>
    
                } 
    
                else
    
                {
    
                    <li class="@(childPage.IsAncestorOrSelf(CurrentPage) ? "selected" : null)">
    
                        <a href="@childPage.Url">@childPage.Name</a>
    
                    </li>
    
                } 
    
            }            
    
        </ul>
    
    }
    

    Hope this helps, perhaps this can be done in a much better way.

    /Dennis

  • Nico Viergever 20 posts 81 karma points
    May 27, 2015 @ 12:22
    Nico Viergever
    0

    Same problem as before, Dennis. No menu when on a page under the Landing Page, e.g. "The Starter Kit".

    Difficult question, is it?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 27, 2015 @ 12:27
    Dennis Aaen
    0

    Hi Nico,

    But does this have any children at all and if it not, what should then be showing?

    /Dennis

  • Nico Viergever 20 posts 81 karma points
    May 27, 2015 @ 12:30
    Nico Viergever
    0

    I was looking for exactly the same menu as on the landing page.

    So on both the Landing Page and all its childeren:

    Learn (not shown now) - The starter kit - Basics - Masterclasses

     

    And if present their children

Please Sign in or register to post replies

Write your reply to:

Draft