How can I determine if the row being returned from a table field in a for loop is the last row?

2 Answers 2


Twig's for loop exposes a loop variable with a number of useful properties, including last:

{% for row in table %}
    {% if loop.last %}
        // Do stuff
    {% endif %}
{% endfor %}

See the official Twig docs for more information on the loop variable and its properties (first, last, index etc).


In any for loop you can use the loop variable that twig gives you.

For example:

{% for row in myTable %}
  {% if loop.last %}
    This is the last row
  {% else %}
    This is anything but the last row
  {% endif %}
{% endfor %}

More information on the loop variable can be found in the twig docs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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