I have the following Jinja template:
{% set mybool = False %}
{% for thing in things %}
{%
Here's the general case for anyone wanting to use the namespace()
object to have a variable persist outside of a for
loop.
{% set accumulator = namespace(total=0) %}
{% for i in range(0,3) %}
{% set accumulator.total = i + accumulator.total %}
{{accumulator.total}}
{% endfor %}` {# 0 1 3 #}
{{accumulator.total}} {# 3 (accumulator.total persisted past the end of the loop) #}