Copied to clipboard

Flag this post as spam?

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


  • Mark Watson 118 posts 384 karma points
    Mar 08, 2019 @ 04:40
    Mark Watson
    0

    disable parent nav link

    I am using a partial below to create the main navigation

    <!-- Nav -->
    
      @* If the Url of the current page is "/" then we want to add the class "current_page_item" *@ @* Otherwise, we set the class to null, that way it will not even be added to the
    • element *@
    • Home
    • @foreach (var item in menuItems) { var childrenItems = item.Children.Where("UmbracoNaviHide == false");
    • @item.Name @createSubmenu(childrenItems, item.Id)
    • }

    @helper createSubmenu(IEnumerable

      @foreach (var node in nodes) { var childrenItems = node.Children.Where("UmbracoNaviHide == false");
    • @node.Name @createSubmenu(childrenItems, node.Id)
    • }
    } }

    I have a parent menu "services" with child/sub menus "pavers", "tiles" etc. the parent menu services links to the service page. However there is nothing on this page so I would like to disable the link to the services page, /services/.

    How do i do that?

  • Asembli 85 posts 259 karma points
    Mar 08, 2019 @ 06:31
    Asembli
    0

    Hi, you can do like this:

    @model IPublishedContent
    
    @{
    IPublishedContent parent = [your top menu document];
    }
    
    @functions {
        // select all items up-tree
        public bool IsMenuInPath(IPublishedContent menuPage)
        {
            if (menuPage.IsAncestorOrSelf(Model))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    
    
    @helper DrawMenuLevel(IPublishedContent parent, int level, bool letShow)
    {
        IEnumerable<IPublishedContent> children = parent.Children(x => x.IsVisible() && !A8.Common.VerifyTrue(x.GetPropertyValue<bool>("seoHideInMenu")));
        if (children != null && children.Any())
        {
            <ul class="menu-level-@(level)" @Html.Raw(letShow ? "style=\"display: block;\"" : string.Empty)>
                @foreach (IPublishedContent child in children)
                {
                    <li class="menu-level-@(level) @(level == 0 ? "title-font_family" : string.Empty)">
                        <a href="@(child.DocumentTypeAlias == "redirect" ? "javascript:;" : child.Url)" title="@HttpUtility.HtmlEncode(child.Name)" class="menu-item @(Model.Id == child.Id ? "menu-item-active" : string.Empty)">@child.Name</a>
                        @{
                            IEnumerable<IPublishedContent> childChildren = child.Children(x => x.IsVisible() && !A8.Common.VerifyTrue(x.GetPropertyValue<bool>("seoHideInMenu")));
                            bool isMenuInPath = IsMenuInPath(child);
                            if (childChildren != null && childChildren.Any())
                            {
                                <span class="menu-plus-minus @(isMenuInPath ? "active" : string.Empty)"></span>
                                @DrawMenuLevel(child, level + 1, isMenuInPath)
                            }
                        }
    
                    </li>
                }
            </ul>
        }
    }
    
    ...
    
    <nav>
    @DrawMenuLevel(parent, 0, false)
    </nav>
    

    the cruical line for you is child.DocumentTypeAlias == "redirect" where you can put whatever flag you want, maybe some property from that document eg: x.GetPropertyValue

    Best regards,

    /Asembli

  • Mark Watson 118 posts 384 karma points
    Mar 25, 2019 @ 00:59
    Mark Watson
    0

    Thanks Asembli. I am new to Umbraco so this is all new to me.

    I tried this but got an error

    Line 28:     IEnumerable<IPublishedContent> children = parent.Children(x => x.IsVisible() && !A8.Common.VerifyTrue(x.GetPropertyValue<bool>("seoHideInMenu")));
    

    I used

    IPublishedContent parent = Model.Content.AncestorOrSelf("Home");
    

    I am using the nav in a partial.

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Mar 25, 2019 @ 02:39
    Søren Gregersen
    0

    what is the error?

Please Sign in or register to post replies

Write your reply to:

Draft