summaryrefslogtreecommitdiff
path: root/docs/templates.txt
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-06-08 03:33:21 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-06-08 03:33:21 +0000
commite5cd46d6d1ecf9a388d5b2b9e33f815803fcd1c4 (patch)
treeaa968ebf0bfac05e22b33e58d1562f7cf266bc50 /docs/templates.txt
parent14c159d21d89d32b23639dd15d0884c21597c4fa (diff)
downloaddjango-e5cd46d6d1ecf9a388d5b2b9e33f815803fcd1c4.tar.gz
Fixed #2026 -- Added support for 'and' in template 'if' tags, added dozens of unit tests and updated docs. Thanks, ckknight
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3108 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/templates.txt')
-rw-r--r--docs/templates.txt28
1 files changed, 20 insertions, 8 deletions
diff --git a/docs/templates.txt b/docs/templates.txt
index c191b409f4..69251df8bb 100644
--- a/docs/templates.txt
+++ b/docs/templates.txt
@@ -454,8 +454,12 @@ displayed by the ``{{ athlete_list|length }}`` variable.
As you can see, the ``if`` tag can take an option ``{% else %}`` clause that
will be displayed if the test fails.
-``if`` tags may use ``or`` or ``not`` to test a number of variables or to negate
-a given variable::
+``if`` tags may use ``and``, ``or`` or ``not`` to test a number of variables or
+to negate a given variable::
+
+ {% if athlete_list and coach_list %}
+ Both athletes and coaches are available.
+ {% endif %}
{% if not athlete_list %}
There are no athletes.
@@ -468,16 +472,24 @@ a given variable::
{% if not athlete_list or coach_list %}
There are no athletes or there are some coaches (OK, so
writing English translations of boolean logic sounds
- stupid; it's not my fault).
+ stupid; it's not our fault).
+ {% endif %}
+
+ {% if athlete_list and not coach_list %}
+ There are some athletes and absolutely no coaches.
{% endif %}
-For simplicity, ``if`` tags do not allow ``and`` clauses; use nested ``if``
-tags instead::
+``if`` tags don't allow ``and`` and ``or`` clauses within the same tag, because
+the order of logic would be ambiguous. For example, this is invalid::
+
+ {% if athlete_list and coach_list or cheerleader_list %}
+
+If you need to combine ``and`` and ``or`` to do advanced logic, just use nested
+``if`` tags. For example::
{% if athlete_list %}
- {% if coach_list %}
- Number of athletes: {{ athlete_list|length }}.
- Number of coaches: {{ coach_list|length }}.
+ {% if coach_list or cheerleader_list %}
+ We have athletes, and either coaches or cheerleaders!
{% endif %}
{% endif %}