Here is my solution:
Put all the counters in the dictionary:
{% set counter = { 'something1': 0, 'something2': 0, 'etc': 0, } %}
Define a macro to enlarge it easily:
{% macro increment(dct, key, inc=1)%} {% if dct.update({key: dct[key] + inc}) %} {% endif %} {% endmacro %}
Now that you want to increment the "something1" counter, simply do:
{{ increment(counter, 'something1') }}
Jahid Aug 11 '17 at 20:06 on 2017-08-11 20:06
source share