From 793773f1910645cbe7b24585a00aefc2508a7a58 Mon Sep 17 00:00:00 2001 From: Ian Dundas Date: Wed, 12 Jul 2017 11:46:43 +0200 Subject: [PATCH] docs: Added example to show use of `forloop.x`in a for loop (#123) --- docs/builtins.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/builtins.rst b/docs/builtins.rst index e9e9b9d..7b6d4ea 100644 --- a/docs/builtins.rst +++ b/docs/builtins.rst @@ -59,6 +59,23 @@ The for block sets a few variables available within the loop: - ``last`` - True if this is the last time through the loop - ``counter`` - The current iteration of the loop +For example: + +.. code-block:: html+django + + {% 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 %} + + ``if`` ~~~~~~