Changeset 5815
- Timestamp:
- 08/06/07 00:28:45 (1 year ago)
- Files:
-
- django/trunk/django/template/defaulttags.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/template/defaulttags.py
r5609 r5815 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 to653 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 %} … … 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:: 669 670 {% if athlete_list %} 671 {% if coach_list %} 672 Number of athletes: {{ athlete_list|count }}. 673 Number of coaches: {{ coach_list|count }}. 674 {% endif %} 671 {% if athlete_list and not coach_list %} 672 There are some athletes and absolutely no coaches. 675 673 {% endif %} 674 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! 687 {% endif %} 688 {% endif %} 676 689 """ 677 690 bits = token.contents.split()
