Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jinja loop.index does not print

When running the following jinja code, I only get "Column info" printed. Why the index does not appears ?

{% for field in columns_form %}
    {% if 'title_' in field.name %}
        <td>Column {{ loop.index }} info</td>
    {% endif %}
{% endfor %}
like image 629
Benjamin Avatar asked Nov 28 '22 06:11

Benjamin


1 Answers

It sounds like the template is being treated as a Django template, not a Jinja template.

Using {{ loop.index }} should work in a Jinja template, but wouldn't work in a Django template, where you would use {{ forloop.counter }} instead.

like image 87
Alasdair Avatar answered Nov 30 '22 20:11

Alasdair