I would like to set a flag inside a Jinja2 template for loop and later display something or not depending on the flag like so:
{% set foobar = False %}
{% for foo in foos %}
[... render the foo here ...]
{% if foo.bar %}
{% set foobar = True %}
{% endif %}
{% endfor %}
[...]
{% if foobar %}
At least one of the foos is bar!!!
{% endif %}
It seems however that this is impossible and the foobar
set within the loop is not the same as the one outside the loop. Even if foo.bar
evaluates to True for one of the foos, foobar
remains False outside the loop.
Is there any way of doing this with template code only and without iterating over all the foos again?