Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #5006 -- Fixed incorrect/outdated docstring for the 'if' templa…

…te tag. Thanks, Thomas Petazzoni

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5815 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3517550dacaed6933c390d2d1f7e78c67c04aec4 1 parent b304ebb
Adrian Holovaty authored August 06, 2007

Showing 1 changed file with 22 additions and 9 deletions. Show diff stats Hide diff stats

  1. 31  django/template/defaulttags.py
31  django/template/defaulttags.py
@@ -649,8 +649,8 @@ def do_if(parser, token):
649 649
     As you can see, the ``if`` tag can take an option ``{% else %}`` clause that
650 650
     will be displayed if the test fails.
651 651
 
652  
-    ``if`` tags may use ``or`` or ``not`` to test a number of variables or to
653  
-    negate a given variable::
  652
+    ``if`` tags may use ``or``, ``and`` or ``not`` to test a number of
  653
+    variables or to negate a given variable::
654 654
 
655 655
         {% if not athlete_list %}
656 656
             There are no athletes.
@@ -660,19 +660,32 @@ def do_if(parser, token):
660 660
             There are some athletes or some coaches.
661 661
         {% endif %}
662 662
 
  663
+        {% if athlete_list and coach_list %}
  664
+            Both atheletes and coaches are available.
  665
+        {% endif %}
  666
+
663 667
         {% if not athlete_list or coach_list %}
664 668
             There are no athletes, or there are some coaches.
665 669
         {% endif %}
666 670
 
667  
-    For simplicity, ``if`` tags do not allow ``and`` clauses. Use nested ``if``
668  
-    tags instead::
  671
+        {% if athlete_list and not coach_list %}
  672
+            There are some athletes and absolutely no coaches.
  673
+        {% endif %}
669 674
 
670  
-        {% if athlete_list %}
671  
-            {% if coach_list %}
672  
-                Number of athletes: {{ athlete_list|count }}.
673  
-                Number of coaches: {{ coach_list|count }}.
674  
-            {% endif %}
  675
+    ``if`` tags do not allow ``and`` and ``or`` clauses with the same
  676
+    tag, because the order of logic would be ambigous. For example,
  677
+    this is invalid::
  678
+
  679
+    {% if athlete_list and coach_list or cheerleader_list %}
  680
+
  681
+    If you need to combine and and or to do advanced logic, just use
  682
+    nested if tags. For example:
  683
+
  684
+    {% if athlete_list %}
  685
+        {% if coach_list or cheerleader_list %}
  686
+            We have athletes, and either coaches or cheerleaders!
675 687
         {% endif %}
  688
+    {% endif %}
676 689
     """
677 690
     bits = token.contents.split()
678 691
     del bits[0]

0 notes on commit 3517550

Please sign in to comment.
Something went wrong with that request. Please try again.