<p>Wow - thanks for listening ;-)</p>

<p>I solved it like this:</p>

<pre><code>{# loop through continents #}
{% for entry in craft.entries.section('destinations').type('continent').find() %}   
    {# only show links to continent pages if it has any travelguides #}
    {% if entry.hasDescendants() %}
        {% set continentID = entry.id %}
        {% if entry.howLongWillYouBeGoing == 'mediumStay' in craft.entries.section('destinations').descendantOf(continentID) %}
            {# if subpage is marked as mediumstay, show a link to it #}
            &lt;li&gt;&lt;a href="{{ entry.url }}" {% if craft.request.firstSegment == entry.slug %}class="is-active"{% endif %}&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;  
        {% else %} 
            {# if it's not a mediumStay, just show the text #}
            &lt;li&gt;{{ entry.title }}&lt;/li&gt;
        {% endif %} 
    {% else %} 
        &lt;li&gt;{{ entry.title }}&lt;/li&gt;
    {% endif %}
{% endfor %} 
</code></pre>

<p></p>

CC BY-SA 3.0
2017-02-23T21:17:33.497Z
2017-02-23T21:17:33.497Z
Anneke Sinnema
<p>Whew, complicated thing to described in a short subject line! :) </p>

<p>Okay, so I have a structure like this:</p>

<hr>

<ul>
<li>Asia

<ul>
<li>Peking  

<ul>
<li>weekend ( field <code>howLongWillYouBeGoing</code> == 'shortStay' )</li>
<li>long weekend ( field <code>howLongWillYouBeGoing</code> == 'mediumStay' )</li>
<li>week ( field <code>howLongWillYouBeGoing</code> == 'longStay' )</li>
</ul></li>
</ul></li>
<li>Europe

<ul>
<li>Peking  

<ul>
<li>weekend ( field <code>howLongWillYouBeGoing</code> == 'shortStay' )</li>
</ul></li>
</ul></li>
<li>South America
(no subpages)</li>
</ul>

<hr>

<p>I have a navigation bar that just lists the continents and turns them into a link as soon as it has descendants. When it doesn't have descendants, it just shows the continent name as a non-clickable text.</p>

<p>Now this is the thing. I have used the following code, but it doesn't work. It still shows Europe in this example as a link, even though I believe the conditions are not met. I would LOVE love love any input because I've been staring myself blind on this the last few hours :)</p>

<pre><code>{# loop through continents #}
{% for entry in craft.entries.section('destinations').type('continent').find() %}
    {# only show links to continent pages if it has any travelguides #}
    {% if entry.hasDescendants(3) %}

        {% set mediumStay = 0 %}
        {% for subPage in entry.getDescendants(2) %}
            {% if subPage.howLongWillYouBeGoing == 'mediumStay' %}
                {% set mediumStay = 1 %}
            {% endif %}
        {% endfor %}

        {% if mediumStay == 1 %}
            {# if subpage is marked as mediumstay, show a link to it #}
            &lt;li&gt;&lt;a href="{{ entry.url }}" {% if craft.request.firstSegment == entry.slug %}class="is-active"{% endif %}&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
        {% endif %}
    {% else %}
        &lt;li&gt;{{ entry.title }}&lt;/li&gt;
    {% endif %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-03-24T11:02:21.833Z
@lindsey-d thank you for cleaning up my code! I was struggling a bit there.
Anneke Sinnema
<templating><entries><structure>
Check if entry has a descendant with a certain field enabled
# Check if entry has a descendant with a certain field enabled

(Asked by: username_0 on 2017-02-23)

Whew, complicated thing to described in a short subject line! :) 
Okay, so I have a structure like this:


Asia


Peking  


weekend ( field howLongWillYouBeGoing == 'shortStay' )
long weekend ( field howLongWillYouBeGoing == 'mediumStay' )
week ( field howLongWillYouBeGoing == 'longStay' )


Europe


Peking  


weekend ( field howLongWillYouBeGoing == 'shortStay' )


South America
(no subpages)


I have a navigation bar that just lists the continents and turns them into a link as soon as it has descendants. When it doesn't have descendants, it just shows the continent name as a non-clickable text.
Now this is the thing. I have used the following code, but it doesn't work. It still shows Europe in this example as a link, even though I believe the conditions are not met. I would LOVE love love any input because I've been staring myself blind on this the last few hours :)
{# loop through continents #}
{% for entry in craft.entries.section('destinations').type('continent').find() %}
    {# only show links to continent pages if it has any travelguides #}
    {% if entry.hasDescendants(3) %}

        {% set mediumStay = 0 %}
        {% for subPage in entry.getDescendants(2) %}
            {% if subPage.howLongWillYouBeGoing == 'mediumStay' %}
                {% set mediumStay = 1 %}
            {% endif %}
        {% endfor %}

        {% if mediumStay == 1 %}
            {# if subpage is marked as mediumstay, show a link to it #}
            {{ entry.title }}
        {% endif %}
    {% else %}
        {{ entry.title }}
    {% endif %}
{% endfor %}

**Tags:** templating, entries, structure
> **Comments:**
> **username_0**: @lindsey-d thank you for cleaning up my code! I was struggling a bit there.  

---

## 1 answers

### Answer by username_0 on 2017-02-23. Score: 1 | Accepted answer

Wow - thanks for listening ;-)
I solved it like this:
{# loop through continents #}
{% for entry in craft.entries.section('destinations').type('continent').find() %}   
    {# only show links to continent pages if it has any travelguides #}
    {% if entry.hasDescendants() %}
        {% set continentID = entry.id %}
        {% if entry.howLongWillYouBeGoing == 'mediumStay' in craft.entries.section('destinations').descendantOf(continentID) %}
            {# if subpage is marked as mediumstay, show a link to it #}
            {{ entry.title }}  
        {% else %} 
            {# if it's not a mediumStay, just show the text #}
            {{ entry.title }}
        {% endif %} 
    {% else %} 
        {{ entry.title }}
    {% endif %}
{% endfor %}


---

