Ticket #5006: template-if-doc-fix.diff
File template-if-doc-fix.diff, 2.0 KB (added by , 17 years ago) |
---|
-
django/template/defaulttags.py
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 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 %} 656 656 There are no athletes. … … 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]