diff options
| author | Luke Plant <L.Plant.98@cantab.net> | 2009-12-09 22:40:36 +0000 |
|---|---|---|
| committer | Luke Plant <L.Plant.98@cantab.net> | 2009-12-09 22:40:36 +0000 |
| commit | 2c2f5aee4d44836779fcd74c7782368914f9cfd1 (patch) | |
| tree | 686d60b434ffe9ebcc019ef61208e5cd45921ab9 /docs/topics | |
| parent | 25020ddb05543fff1c37d77b49bd937fd2bbb170 (diff) | |
Implemented 'smart if' template tag, allowing filters and various operators to be used in the 'if' tag
Thanks to Chris Beaven for the initial patch, Fredrik Lundh for the basis
of the parser methodology and Russell Keith-Magee for code reviews.
There are some BACKWARDS INCOMPATIBILITIES in rare cases - in particular, if
you were using the keywords 'and', 'or' or 'not' as variable names within
the 'if' expression, which was previously allowed in some cases.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@11806 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/topics')
| -rw-r--r-- | docs/topics/templates.txt | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/docs/topics/templates.txt b/docs/topics/templates.txt index 1c8b63c61e..41cb94a56d 100644 --- a/docs/topics/templates.txt +++ b/docs/topics/templates.txt @@ -187,8 +187,8 @@ tags: <li>{{ athlete.name }}</li> {% endfor %} </ul> - - :ttag:`if` and :ttag:`else` + + :ttag:`if` and ``else`` Evaluates a variable, and if that variable is "true" the contents of the block are displayed:: @@ -200,20 +200,15 @@ tags: In the above, if ``athlete_list`` is not empty, the number of athletes will be displayed by the ``{{ athlete_list|length }}`` variable. - - :ttag:`ifequal` and :ttag:`ifnotequal` - Display some contents if two arguments are or are not equal. For example:: - {% ifequal athlete.name coach.name %} - ... - {% endifequal %} + You can also use filters and various operators in the ``if`` tag:: - Or:: + {% if athlete_list|length > 1 %} + Team: {% for athlete in athlete_list %} ... {% endfor %} + {% else %} + Athlete: {{ athlete_list.0.name }} + {% endif %} - {% ifnotequal athlete.name "Joe" %} - ... - {% endifnotequal %} - :ttag:`block` and :ttag:`extends` Set up `template inheritance`_ (see below), a powerful way of cutting down on "boilerplate" in templates. |
