Anonymous Anonymous - 1 year ago
960 0

Example how to detect the last item in a loop in Twig.

Twig

Twig - how to detect last item in loop

{% set numberOfItems = myArray|length %}

{% for item in myArray %}

    {% if numberOfItems == loop.index %}
    
        Last item
    
{% else %}

        Not last item

    {% endif %}

{% endfor %}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download