Copied to clipboard

Flag this post as spam?

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


  • Martin 278 posts 662 karma points
    Mar 20, 2018 @ 13:32
    Martin
    0

    Navigation - Check If Children Are Visible

    Hi All,

    I'm looking for some help with filtering a navigation dropdown.

    I have a umbracoNaviHide property on each document type. I want to be able to check if a level 3 child is visible.

    Ive added .Where("Visible") to the if statement instead of Any(), but I get the error -

    Cannot implicitly convert type 'System.Linq.IQueryable

    Any help would be grateful.

    Martin

     @foreach (var level3 in level2.Children.Where("Visible"))
        {
            if (level3.Children.Any())
            {
                <li class="has-children">
                    <a href="#3">I Have Children</a>
                </li>
            }
            else
            {
                <li>
                    <a href="">I Have No Children or All Children Are Hidden </a>
                </li>
            }
        }
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 20, 2018 @ 13:37
    Alex Skrypnyk
    100

    Hi Martin

    Use this code:

    @foreach (var level3 in level2.Children.Where(x => x.IsVisible()))
    {
        if (level3.Children.Where(x => x.IsVisible().Any())
        {
            <li class="has-children">
                <a href="#3">I Have Children</a>
            </li>
        }
        else
        {
            <li>
                <a href="">I Have No Children or All Children Are Hidden </a>
            </li>
        }
    }
    

    By the way, what is the type of level2?

    Thanks,

    Alex

  • Martin 278 posts 662 karma points
    Mar 20, 2018 @ 13:48
    Martin
    0

    Hi Alex,

    Thanks for that.

    Yeah my level 2 is just the same. I dont think i could use a helper, as each level has a different styling. So it was easier to just build out each level.

Please Sign in or register to post replies

Write your reply to:

Draft