Little Code
Little Code

Reputation: 1545

Simple counter loop in Jinja?

Looking through the docs (https://jinja.palletsprojects.com/en/2.10.x/templates/), all the examples seem to be showing using for loops to iterate through lists.

I just want to have a simple numeric iterator, i.e. for ($i = 1; $i <= 10; $i++).

Is this possible in Jinja ?

Upvotes: 2

Views: 317

Answers (1)

larsks
larsks

Reputation: 311387

You can use the range function to generate a list of integers. So for example:

{% for i in range(10) %}
{{ i }}
{% endfor %}

Results in:


0

1

2

3

4

5

6

7

8

9

Upvotes: 2

Related Questions