Copied to clipboard

Flag this post as spam?

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


  • Sharmarke Hujale 103 posts 346 karma points
    Apr 30, 2016 @ 21:03
    Sharmarke Hujale
    0

    Getting the "Home" node in dynamically in the navigation menu

    Hi guys!

    I want to have my home node dynamically in my navigation menu - but have do I achieve that?

    This is my code:

    @{ var selection = CurrentPage.Site().Children.Where("Visible"); }
    
    <ul class="nav navbar-nav">
     @*<li><a class="page-scroll" href="/forside/">forside</a></li>*@
     @foreach (var item in selection)
     {
        <li class="@(item.IsAncestorsOrSelf(CurrentPage) ? "active" : null)">
            <a href="@item.Url">@item.Name</a>
        </li>
     }
    <li><a class="page-scroll" href="#kontakt">Kontakt os</a></li>
    

    I could just hardcode my home node, but then, I can't use my the umbracoNaviHide function.

    So can anyone please help with this?

    Thanks in advance,

    //Sharmarke

  • Aristotelis Pitaridis 84 posts 402 karma points
    May 01, 2016 @ 08:22
    Aristotelis Pitaridis
    0

    I have not tested it but it should work.

    @{
        var RootNode = CurrentPage.AncestorsOrSelf().Last();
    }
    
  • Sharmarke Hujale 103 posts 346 karma points
    May 01, 2016 @ 19:02
    Sharmarke Hujale
    0

    Hi Aristotelis,

    I've tried your solution:

    @{ 
    //var selection = CurrentPage.Site().Children.Where("Visible");
    var RootNode = CurrentPage.AncestorsOrself.First().Where("Visible");
    }
    
    <ul class="nav navbar-nav">
     @*<li><a class="page-scroll" href="/forside/">forside</a></li>*@
           @foreach (var item in RootNode)
            {
              <li class="@(item.IsAncestorsOrSelf(CurrentPage) ? "active" : null)">
              <a href="@item.Url">@item.Name</a>
              </li>
            }
        <li><a class="page-scroll" href="#kontakt">Kontakt os</a></li>
    

    But all of my menu items disappeared in my navigation - did I do something wrong?

    //Sharmarke

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    May 01, 2016 @ 19:09
    Dennis Adolfi
    100

    Hi Sharmarke!!

    Try this:

     @{ 
    var home = CurrentPage.Site();    
    var children = home.Children.Where("Visible");    
        }
    
        <ul class="nav navbar-nav">
         <li><a class="page-scroll" href="@home.Url">@home.Name</a></li>
               @foreach (var item in children)
                {
                  <li class="@(item.Id == CurrentPage.Id ? "active" : "")">
                  <a href="@item.Url">@item.Name</a>
                  </li>
                }
            <li><a class="page-scroll" href="#kontakt">Kontakt os</a></li></ul>
    
  • Sharmarke Hujale 103 posts 346 karma points
    May 01, 2016 @ 19:30
    Sharmarke Hujale
    1

    Hi Dennis!!

    Thank you very much for your help and time - your solution worked very well for me - I appreciate it!

    //Sharmarke

  • Dennis Adolfi 1082 posts 6449 karma points MVP 6x c-trib
    May 01, 2016 @ 19:52
    Dennis Adolfi
    0

    Awsome Sharmarke, great to hear that it worked out for you and glad i could help. Good luck with the rest of you site and have a great day!!

  • Sharmarke Hujale 103 posts 346 karma points
    May 01, 2016 @ 20:03
    Sharmarke Hujale
    1

    Thanks - and you too!

Please Sign in or register to post replies

Write your reply to:

Draft