diff options
Diffstat (limited to 'docs/templates.txt')
| -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 ~~~~~~~ |
