Ticket #5006: template-if-doc-fix.diff

File template-if-doc-fix.diff, 2.0 KB (added by Thomas Petazzoni <thomas.petazzoni@…>, 17 years ago)

Proposed patch

  • django/template/defaulttags.py

     
    649649    As you can see, the ``if`` tag can take an option ``{% else %}`` clause that
    650650    will be displayed if the test fails.
    651651
    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::
    654654
    655655        {% if not athlete_list %}
    656656            There are no athletes.
     
    660660            There are some athletes or some coaches.
    661661        {% endif %}
    662662
     663        {% if athlete_list and coach_list %}
     664            Both atheletes and coaches are available.
     665        {% endif %}
     666
    663667        {% if not athlete_list or coach_list %}
    664668            There are no athletes, or there are some coaches.
    665669        {% endif %}
    666670
    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 %}
    669674
    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!
    675687        {% endif %}
     688    {% endif %}
    676689    """
    677690    bits = token.contents.split()
    678691    del bits[0]
Back to Top