<p>What you could do is to get all the descendants and loop them to check if at least one has that lightswitch not set.</p>

<pre><code>{% set showDropdown = 0 %}
{% for subPage in page.getDescendants() if subPage.genericHideFromNavigation == 0 %}
    {% set showDropdown = 1 %}
{% endif %}

&lt;li class="{% if showDropdown %}has-dropdown{% endif %}"&gt;&lt;/li&gt;
</code></pre>

CC BY-SA 3.0
2014-11-15T21:50:52.100Z
2014-11-15T21:50:52.100Z
carlcs
<p>I'm building a navigation menu with 2 levels.  </p>

<p>I have a contact page with a subpage thank you, which is hidden.  </p>

<p>I hide pages from the menu using a lightswitch option and filter these pages out in my entries call.  </p>

<p>However I check if a page has subpages using hasDescendants(), and if the page does, I add the class "has-dropdown" but my contact menu item contains the class "has-dropdown" too which technically is correct as it has a subpage but is it possible to filter with hasDescendants() ?</p>

<pre><code>{% set pages = craft.entries.find({section: "page", genericHideFromNavigation: "[0]"}) %}
{% if pages | length %}
    &lt;ul class="main-nav"&gt;
        {% nav page in pages %}
            &lt;li class="{% if page.hasDescendants() %}has-dropdown{% endif %}"&gt;
                &lt;a href="{{ page.url }}" title="{{ page.title }}"&gt;{{ page.title }}&lt;/a&gt;

                {% ifchildren %}
                    &lt;ul class="dropdown"&gt;
                        {% children %}
                    &lt;/ul&gt;
                {% endifchildren %}
            &lt;/li&gt;
        {% endnav %}
    &lt;/ul&gt;
{% endif %}
</code></pre>

<navigation>
Is it possible to filter with hasDescendants?
# Is it possible to filter with hasDescendants?

(Asked by: username_0 on 2014-11-15)

I'm building a navigation menu with 2 levels.  
I have a contact page with a subpage thank you, which is hidden.  
I hide pages from the menu using a lightswitch option and filter these pages out in my entries call.  
However I check if a page has subpages using hasDescendants(), and if the page does, I add the class "has-dropdown" but my contact menu item contains the class "has-dropdown" too which technically is correct as it has a subpage but is it possible to filter with hasDescendants() ?
{% set pages = craft.entries.find({section: "page", genericHideFromNavigation: "[0]"}) %}
{% if pages | length %}
    
        {% nav page in pages %}
            
                {{ page.title }}

                {% ifchildren %}
                    
                        {% children %}
                    
                {% endifchildren %}
            
        {% endnav %}
    
{% endif %}

**Tags:** navigation

---

## 1 answers

### Answer by username_1 on 2014-11-15. Score: 2 | Accepted answer

What you could do is to get all the descendants and loop them to check if at least one has that lightswitch not set.
{% set showDropdown = 0 %}
{% for subPage in page.getDescendants() if subPage.genericHideFromNavigation == 0 %}
    {% set showDropdown = 1 %}
{% endif %}


---

