How do you index on a jinja template?

If you really want the index, you could just loop on one of the variables and then uses Jinja’s loop.index0 feature (returns the current index of the loop starting at 0 (loop.index does the same thing, starting at 1)

For example:

{% for item in list1 %}

    {{ item }}
    {{ list2[loop.index0] }}
    {{ list3[loop.index0] }}

{% endfor %}

This assumes your lists are all asserted to be the same length before setting the template, or you’ll encounter problems.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)