Display a an area if there is a page available


<!-- Navigation 4 -->
            <section>

                {% for p in pages.children %}

                    {% if (p.active or p.activeChild) %}
                        {% for c in p.children %}
                            {% if (c.active or c.activeChild) %}

                                {% for cc in c.children %}
                                    {% if (cc.active or cc.activeChild) %}
                    
                                        {% for ccc in cc.children %}
                                            {% if (ccc.active) %}
                                                <a class="active" href="{{ ccc.url }}">{{ ccc.title }}</a>
                                            {% else %}
                                                <a href="{{ ccc.url }}">{{ ccc.title }}</a>
                                            {% endif %}
                                        {% endfor %} 
                        
                                    {% endif %}
                                 {% endfor %}
                

                            {% endif %}
                        {% endfor %}
                    {% endif %}

                {% endfor %}

            </section>

how can i display only the section if there is a childpage available?

thanks!

Hi! I’m not completely sure what you want to accomplish, but you can use children.count to see how many children there are. So you could do that loop before the section starts to detect if there are children on the third level like your section seems to display and wrap the section in an if test like so:

<!-- Navigation 4 -->
{% set child_available = false %}
{% for p in pages.children %}
    {% if (p.active or p.activeChild) %}
        {% for c in p.children %}
            {% if (c.active or c.activeChild) %}
                {% for cc in c.children %}
                    {% if (cc.active or cc.activeChild) %}
                        {% if (cc.children > 0) %}
                            {# OK, we found a child on the third level, set the variable to true! #}
                            {{ set child_available = true }}
                        {% endif %}
                    {% endif %}
                 {% endfor %}
            {% endif %}
        {% endfor %}
    {% endif %} 
{% endfor %}

{% if (child_available) %}
<section>

    {% for p in pages.children %}

        {% if (p.active or p.activeChild) %}
            {% for c in p.children %}
                {% if (c.active or c.activeChild) %}

                    {% for cc in c.children %}
                        {% if (cc.active or cc.activeChild) %}
        
                            {% for ccc in cc.children %}
                                {% if (ccc.active) %}
                                    <a class="active" href="{{ ccc.url }}">{{ ccc.title }}</a>
                                {% else %}
                                    <a href="{{ ccc.url }}">{{ ccc.title }}</a>
                                {% endif %}
                            {% endfor %}
            
                        {% endif %}
                     {% endfor %}
    

                {% endif %}
            {% endfor %}
        {% endif %}

    {% endfor %}

</section>
{% endif %}

Does that answer your question?

sorry and thank you, i gonna try it :smiley:

<!-- Navigation 4 -->
{% set child_available = false %}
{% for p in pages.children %}
    {% if (p.active or p.activeChild) %}
        {% for c in p.children %}
            {% if (c.active or c.activeChild) %}
                {% for cc in c.children %}
                    {% if (cc.active or cc.activeChild) %}
                        {% if (cc.children.count > 0) %}
                            {% set child_available = true %}
                        {% endif %}
                    {% endif %}
                 {% endfor %}
            {% endif %}
        {% endfor %}
    {% endif %}
{% endfor %}

your code had some mistakes, so i’ve overwritten some stuff:


{% if (cc.children.count > 0) %}
{% set child_available = true %}
{% endif %}