Skip to main content
Code cleanup
Source Link
Lindsey D
  • 24.1k
  • 5
  • 54
  • 111
  • Asia
    • Peking
      • weekend ( field howLongWillYouBeGoinghowLongWillYouBeGoing == 'shortStay' )
      • long weekend ( field howLongWillYouBeGoinghowLongWillYouBeGoing == 'mediumStay' )
      • week ( field howLongWillYouBeGoinghowLongWillYouBeGoing == 'longStay' )
  • Europe
    • Peking
      • weekend ( field howLongWillYouBeGoinghowLongWillYouBeGoing == 'shortStay' )
  • South America (no subpages)
{# 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 %}
    {# 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 #}
                <li><a href="{{ entry.url }}" {% if craft.request.firstSegment == entry.slug %}class="is-active"{% endif %}>{{ entry.title }}</a></li>
            {% endif %}
        {% else %}
            <li>{{ entry.title }}</li>
        {% endif %}
    {% endfor %}
    
    • 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)
    {# 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 %}
    • 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)
    {# 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 #}
                <li><a href="{{ entry.url }}" {% if craft.request.firstSegment == entry.slug %}class="is-active"{% endif %}>{{ entry.title }}</a></li>
            {% endif %}
        {% else %}
            <li>{{ entry.title }}</li>
        {% endif %}
    {% endfor %}
    
    Source Link

    Check if entry has a descendant with a certain field enabled

    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 %}