I'm trying to make a mod in jinja2 but no way.
{% set index = 1 %}
option 1:
{% for .... %}
{% if {{index % 3 == 0}} %}
{% endif %}
{% set index = index + 1 %}
{% endfor %}
option 2:
{% for .... %}
{% if index.index is divisibleby 3 %}
{% endif %}
{% set index = index + 1 %}
{% endfor %}
Any idea?
Thanks
You can use the batch
filter:
{% for item_batched in items|batch(3) %}
{% for item in items_batched %}
{% endfor %}
{% endfor %}
http://jinja.pocoo.org/docs/dev/templates/#batch
You just need to remove the {{ }} from your first if statement. This code works...
<!-- {% set index = 9 %} -->
{% set index = 10 %}
{% if index % 3 == 0 %}hi
{% endif %}
{% set index = index + 1 %}
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With