fabpot/Twig — Issue #557: loop.last not working
Author: rochadk
Created: 2011-12-09 21:26:27+00:00
State: open

Hi,

I discovered a strange bug when using v.1.4

The bug occured when I traversed an array of strings, and after each occurence, except for the last, added a comma. However, the first element of the array wouldn't be printed (maybe it doesn't matter which element it is, in my case it was just always the first) and because of that, loop.last didn't evaluate to true.

ex.
array('ignore', 'hello', 'world')

{% for item in array %}
{% if item != 'ignore' %}
{{ item }}
{% if not loop.last %}
,
{% endif %}
{% endif %}
{% endfor %}

(the above example is quickly scrippled, if there's any syntax errors, please consider it pseudo-wise)

I tried removing the "{% if item != 'ignore' %}" and then loop.last works just fine

This issue didn't exist in 1.1 which I've just reverted back to...