feat(for tag): Provide the counter 0 indexed to the context

Closes #121
This commit is contained in:
Kyle Fuller
2017-09-07 18:21:16 +01:00
parent 482d595d01
commit 7b9817ed50
4 changed files with 23 additions and 10 deletions

View File

@@ -57,23 +57,24 @@ The for block sets a few variables available within the loop:
- ``first`` - True if this is the first time through the loop
- ``last`` - True if this is the last time through the loop
- ``counter`` - The current iteration of the loop
- ``counter`` - The current iteration of the loop (1 indexed)
- ``counter0`` - The current iteration of the loop (0 indexed)
For example:
For example:
.. code-block:: html+django
{% for user in users %}
{% if forloop.first %}
This is the first user.
{% endif %}
{% endfor %}
{% for user in users %}
{% if forloop.first %}
This is the first user.
{% endif %}
{% endfor %}
.. code-block:: html+django
{% for user in users %}
This is user number {{ forloop.counter }} user.
{% endfor %}
{% for user in users %}
This is user number {{ forloop.counter }} user.
{% endfor %}
``if``