1

I'm pulling in entries which are the descendant of the current entry id.

This is an example of my structure: Your Adventure > Honeymoon > A trip entry.

The below code is being used on the Honeymoon entry to list any trip entries that are children of the current page.

The below code is working fine apart from the if statement I'm wrapping it all in as I don't want any of the wrapping divs if there are no child pages within 'Honeymoon Trips'.

{% if entry in craft.entries.section('yourAdventures').descendantOf(entry.id)  %}
<!-- This is wrong -->

<div class="section bg-pattern">
    <div class="inner">
         <div class="col-24 gutter-bottom--half ">
            <h3>Available {{ entry.title }}</h3>
            {% for entry in craft.entries.section('yourAdventures').descendantOf( entry.id).find() %}

            ...

            {% endfor %}
        </div>
    </div>
</div>

{% endif %}
4

If I figured out correctly what you want to do - this should do the trick:

{% if entry.children | length  %}

    <div class="section bg-pattern">
        <div class="inner">
             <div class="col-24 gutter-bottom--half">

                <h3>Available {{ entry.title }}</h3>

                {% for child in entry.children %}
                    <p>{{ child.title }}</p>
                {% endfor %}

            </div>
        </div>
    </div>

{% endif %}

entry.children is an alias for entry.getDescendants(1) which returns ElementCriteriaModel


| improve this answer | |
  • Thanks for the reply. This is returning the child of the top level entry when in fact I need the second level down. I'll update my question with my entry structure as I see I've not been very clear. – sarah3585 Feb 6 '17 at 11:37
1

Found a solution, I needed: {% if entry.hasDescendants() %}

{% if entry.hasDescendants() %}

    <div class="section bg-pattern">
        <div class="inner">
            <div class="col-24 gutter-bottom--half ">
                <h3>Available {{ entry.title }}</h3>

                {% for entry in craft.entries.section('yourAdventures').descendantOf( entry.id).find() %}

                    ...

                {% endfor %}
            </div>
        </div>
    </div>

{% endif %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.