summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorSergei Maertens <sergei@maykinmedia.nl>2016-07-03 16:19:06 +0200
committerTim Graham <timograham@gmail.com>2016-09-01 15:52:21 -0400
commit32c02f2a0eaf66e4744f9904eb2a743b87300257 (patch)
tree6c9bd75b70dad3c04110322dbbbc18dc21831355 /docs
parent2cfd48bccd44f52e17851677281cc3fcb0da9d37 (diff)
Fixed #5908 -- Added {% resetcycle %} template tag.
Thanks to Simon Litchfield for the report, Uninen for the initial patch, akaihola, jamesp, b.schube, and Florian Appoloner for subsequent patches, tests, and documentation.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/templates/builtins.txt54
-rw-r--r--docs/releases/1.11.txt3
2 files changed, 57 insertions, 0 deletions
diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
index 9a5bd4abba..61c36f47fb 100644
--- a/docs/ref/templates/builtins.txt
+++ b/docs/ref/templates/builtins.txt
@@ -185,6 +185,9 @@ call to ``{% cycle %}`` doesn't specify ``silent``::
{% cycle 'row1' 'row2' as rowcolors silent %}
{% cycle rowcolors %}
+You can use the :ttag:`resetcycle` tag to make a ``{% cycle %}`` tag restart
+from its first value when it's next encountered.
+
.. templatetag:: debug
``debug``
@@ -994,6 +997,57 @@ attribute, allowing you to group on the display string rather than the
``{{ country.grouper }}`` will now display the value fields from the
``choices`` set rather than the keys.
+.. templatetag:: resetcycle
+
+``resetcycle``
+--------------
+
+.. versionadded:: 1.11
+
+Resets a previous `cycle`_ so that it restarts from its first item at its next
+encounter. Without arguments, ``{% resetcycle %}`` will reset the last
+``{% cycle %}`` defined in the template.
+
+Example usage::
+
+ {% for coach in coach_list %}
+ <h1>{{ coach.name }}</h1>
+ {% for athlete in coach.athlete_set.all %}
+ <p class="{% cycle 'odd' 'even' %}">{{ athlete.name }}</p>
+ {% endfor %}
+ {% resetcycle %}
+ {% endfor %}
+
+This example would return this HTML::
+
+ <h1>José Mourinho</h1>
+ <p class="odd">Thibaut Courtois</p>
+ <p class="even">John Terry</p>
+ <p class="odd">Eden Hazard</p>
+
+ <h1>Carlo Ancelotti</h1>
+ <p class="odd">Manuel Neuer</p>
+ <p class="even">Thomas Müller</p>
+
+Notice how the first block ends with ``class="odd"`` and the new one starts
+with ``class="odd"``. Without the ``{% resetcycle %}`` tag, the second block
+would start with ``class="even"``.
+
+You can also reset named cycle tags::
+
+ {% for item in list %}
+ <p class="{% cycle 'odd' 'even' as stripe %} {% cycle 'major' 'minor' 'minor' 'minor' 'minor' as tick %}">
+ {{ item.data }}
+ </p>
+ {% ifchanged item.category %}
+ <h1>{{ item.category }}</h1>
+ {% if not forloop.first %}{% resetcycle tick %}{% endif %}
+ {% endifchanged %}
+ {% endfor %}
+
+In this example, we have both the alternating odd/even rows and a "major" row
+every fifth row. Only the five-row cycle is reset when a category changes.
+
.. templatetag:: spaceless
``spaceless``
diff --git a/docs/releases/1.11.txt b/docs/releases/1.11.txt
index 3f232a56b8..20f2306ede 100644
--- a/docs/releases/1.11.txt
+++ b/docs/releases/1.11.txt
@@ -313,6 +313,9 @@ Templates
so you can unpack the group object directly in a loop, e.g.
``{% for grouper, list in regrouped %}``.
+* Added a :ttag:`resetcycle` template tag to allow resetting the sequence of
+ the :ttag:`cycle` template tag.
+
Tests
~~~~~