diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2006-11-07 05:36:51 +0000 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2006-11-07 05:36:51 +0000 |
| commit | b1b4e8e7c43bb0ee93646493fcf2df4884c14030 (patch) | |
| tree | c3ed5365124dab962b3e0f2c2066897e1b52a380 /docs | |
| parent | a14dba5eeda3ecd51cc9299878a757df174285a4 (diff) | |
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
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/templates.txt | 29 |
1 files changed, 21 insertions, 8 deletions
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:: +The 'ifchanged' block tag is used within a loop. It has two possible uses. - <h1>Archive for {{ year }}</h1> +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:: - {% for day in days %} - {% ifchanged %}<h3>{{ day|date:"F" }}</h3>{% endifchanged %} - <a href="{{ day|date:"M/d"|lower }}/">{{ day|date:"j" }}</a> - {% endfor %} + <h1>Archive for {{ year }}</h1> + + {% for date in days %} + {% ifchanged %}<h3>{{ date|date:"F" }}</h3>{% endifchanged %} + <a href="{{ date|date:"M/d"|lower }}/">{{ date|date:"j" }}</a> + {% 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 ~~~~~~~ |
