Copied to clipboard

Flag this post as spam?

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


  • Ashkan Taravati 17 posts 37 karma points
    Apr 28, 2014 @ 20:05
    Ashkan Taravati
    0

    navigationbar using codes from sitemap

    Hi I needed a navigation bar to show all anscestors and children (all nodes with tree order) so i combined topnavigation and sitemap code with each other. but i only want the code to statically get the site map of only the homepage not dynamically any currentpage. i need help. i'm not very professional really.maybe it's not even currect to do so but it did answer my needs. this is the current code:

    @inherits UmbracoTemplatePage @{ // Model.Content is the current page that we're on // AncestorsOrSelf is all of the ancestors this page has in the tree // (1) means: go up to level 1 and stop looking for more ancestors when you get there // First() gets the first ancestor found (the home page, on level 1) var homePage = CurrentPage.AncestorsOrSelf(1).First();

    // The menu items we want are all of the children of the homepage
    // We also check if "Hide in navigation" is on in the menu, we shouldn't show hidden items
    var menuItems = homePage.Children.Where("UmbracoNaviHide == false");
    

    }

    <nav id="nav" class="skel-panels-fixed">
    <span id="navlog">
    @* Render the sitemap by passing the root node to the traverse helper *@
    
    @Traverse(CurrentPage.AncestorOrSelf())

    @* Helper method to travers through all descendants @ @helper Traverse(dynamic node) { @ Update the level to reflect how deep you want the sitemap to go *@ var maxLevelForSitemap = 4;

    @* Select visible children *@
    var items = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap);
    
    @* If any items are returned, render a list *@
    if (items.Any())
    {
        <ul>
      <li> <a href="/">صفحۀ اصلی</a></li>
    
            @foreach (var item in items)
            {
                <li class="[email protected]">
                    <a href="@item.Url">@item.Name</a>
    
                    @* Run the traverse helper again *@
                    @Traverse(item)
                </li>
            }
    
        </ul>
    }
    

    }

Please Sign in or register to post replies

Write your reply to:

Draft