Copied to clipboard

Flag this post as spam?

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


  • Matt 308 posts 730 karma points
    Dec 30, 2019 @ 10:43
    Matt
    0

    Navigation with drop down

    Hi all,

    Hope we all had good Christmas,

    I'm working on a simple navigation, I've got the navigation working and if any child are under it will render these in a drop down.

    However what I want to do is be able to disable the dropdown even if there are child under the node.

    What I've done was created a true/false and when this is set to false I want the dropdown not to display. just the node.

    Here is my code;

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    
    @{
        var selection = Umbraco.ContentAtRoot().FirstOrDefault()
        .Children()
        .Where(x => x.IsVisible());
    }
    
    <div data-collapse="medium" data-animation="default" data-duration="400" class="navbar w-nav">
    <div class="w-container">
    <nav role="navigation" class="navmenu w-nav-menu">
        <a href="/" class="navlink w-nav-link">Home</a>
    @foreach (var item in selection)
    {
        var children = item.Children(c => c.IsVisible()).ToArray();
        if (children.Any())
        {
            <div data-hover="1" data-delay="0" class="w-dropdown">
                <div class="navlink w-dropdown-toggle">
                    <a href="@item.Url">
                    <div>@item.Name</div>
                    </a>
                </div>
                <nav class="w-dropdown-list">
                @foreach (var child in children)
                {
    
                        <a class="navlink w-dropdown-link" href="@child.Url" >@child.Name</a>
    
                }
                </nav>
            </div>
        }
        else
        {
            <a href="@item.Url" class="navlink w-nav-link">@item.Name</a>
        }
    }
         </nav>
            <div class="handburger w-nav-button">
              <div class="w-icon-nav-menu"></div>
            </div>
     </div>
    </div> 
    

    I thought I could just change this line

    if (children.Any())
    

    to

    if (!item.Value<bool>("disableDropdown") && (children.Any())
    

    But doesn't seem to be that simple.

    Any help would be great.

    Thanks

  • Matt 308 posts 730 karma points
    Dec 31, 2019 @ 07:54
    Matt
    101

    Changed it to this and worked;

     if (!item.Value<bool>("disableDropdown") && item.Children != null && item.Children.Where(x => x.IsVisible()).Any())
    
  • 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