mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #295 - added {{{forloop.revcounter}}} and {{{forloop.revcounter0}}} variables to for loops. Also updated the docs and added unit tests to verify correct behavior. Thanks, Clint.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@736 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -97,6 +97,9 @@ class ForNode(template.Node):
|
||||
# shortcuts for current loop iteration number
|
||||
'counter0': i,
|
||||
'counter': i+1,
|
||||
# reverse counter iteration numbers
|
||||
'revcounter': len_values - i,
|
||||
'revcounter0': len_values - i - 1,
|
||||
# boolean values designating first and last times through loop
|
||||
'first': (i == 0),
|
||||
'last': (i == len_values - 1),
|
||||
@@ -431,6 +434,10 @@ def do_for(parser, token):
|
||||
========================== ================================================
|
||||
``forloop.counter`` The current iteration of the loop (1-indexed)
|
||||
``forloop.counter0`` The current iteration of the loop (0-indexed)
|
||||
``forloop.revcounter`` The number of iterations from the end of the
|
||||
loop (1-indexed)
|
||||
``forloop.revcounter0`` The number of iterations from the end of the
|
||||
loop (0-indexed)
|
||||
``forloop.first`` True if this is the first time through the loop
|
||||
``forloop.last`` True if this is the last time through the loop
|
||||
``forloop.parentloop`` For nested loops, this is the loop "above" the
|
||||
|
||||
Reference in New Issue
Block a user