I have the following Jinja template:
{% set mybool = False %}
{% for thing in things %}
{%
Answer to a related question: I wanted to have a global counter of the number of times I entered a certain if-block in the template, and ended up with the below.
At the top of the template:
{% set counter = ['1'] %}
In the if-block I want to count:
{% if counter.append('1') %}{% endif %}
When displaying the count:
{{ counter|length }}
The string '1' can be replaced with any string or digit, I believe. It is still a hack, but not a very large one.