Django

Code

Changeset 5815

Show
Ignore:
Timestamp:
08/06/07 00:28:45 (1 year ago)
Author:
adrian
Message:

Fixed #5006 -- Fixed incorrect/outdated docstring for the 'if' template tag. Thanks, Thomas Petazzoni

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/template/defaulttags.py

    r5609 r5815  
    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 %} 
     
    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:: 
    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. 
    675673        {% 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 %} 
    676689    """ 
    677690    bits = token.contents.split()