From b1b4e8e7c43bb0ee93646493fcf2df4884c14030 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Tue, 7 Nov 2006 05:36:51 +0000 Subject: Fixed #2800: the ifchanged tag now can optionally take paramaters to be checked for changing (instead of always using the content). Thanks, Wolfram Kriesing. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4050 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/templates.txt | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'docs') diff --git a/docs/templates.txt b/docs/templates.txt index 92d4b53660..cb06fa27d9 100644 --- a/docs/templates.txt +++ b/docs/templates.txt @@ -525,16 +525,29 @@ ifchanged Check if a value has changed from the last iteration of a loop. -The ``ifchanged`` block tag is used within a loop. It checks its own rendered -contents against its previous state and only displays its content if the value -has changed:: - -

Archive for {{ year }}

- - {% for day in days %} - {% ifchanged %}

{{ day|date:"F" }}

{% endifchanged %} - {{ day|date:"j" }} - {% endfor %} +The 'ifchanged' block tag is used within a loop. It has two possible uses. + +1. Checks its own rendered contents against its previous state and only + displays the content if it has changed. For example, this displays a list of + days, only displaying the month if it changes:: + +

Archive for {{ year }}

+ + {% for date in days %} + {% ifchanged %}

{{ date|date:"F" }}

{% endifchanged %} + {{ date|date:"j" }} + {% endfor %} + +2. If given a variable, check if that variable has changed. For example, the + following shows the date every time it changes, but only shows the hour if both + the hour and the date has changed:: + + {% for date in days %} + {% ifchanged date.date %} {{date.date}} {% endifchanged %} + {% ifchanged date.hour date.date %} + {{date.hour}} + {% endifchanged %} + {% endfor %} ifequal ~~~~~~~ -- cgit v1.3