Twig: loop.last does not work with for ... if syntax
I have a problem with this file : https://github.com/KnpLabs/KnpDisqusBundle/blob/master/Resources/views/js.html.twig , which I reproduced more simply, like this:
{% for test in 0..3 if true %}
{{loop.last}}
{% endfor %}
This raises the following error :
Item “last” for “Array” does not exist
About this issue
- Original URL
- State: closed
- Created 12 years ago
- Comments: 17 (10 by maintainers)
For Drupal, just use the Twig Tweak module’s “children” filter, like so:
@Tchekda See https://twig.symfony.com/doc/2.x/filters/filter.html
End of the issue for me, thank you so much for helping me solving it.