#NEWLINE# @ register . tag ( 'if' ) #NEWLINE# def do_if( parser , token ) : #NEWLINE# #INDENT# '\n    The ``{% if %}`` tag evaluates a variable, and if that variable is "true"\n    (i.e., exists, is not empty, and is not a false boolean value), the\n    contents of the block are output:\n\n    ::\n\n        {% if athlete_list %}\n            Number of athletes: {{ athlete_list|count }}\n        {% elif athlete_in_locker_room_list %}\n            Athletes should be out of the locker room soon!\n        {% else %}\n            No athletes.\n        {% endif %}\n\n    In the above, if ``athlete_list`` is not empty, the number of athletes will\n    be displayed by the ``{{ athlete_list|count }}`` variable.\n\n    As you can see, the ``if`` tag may take one or several `` {% elif %}``\n    clauses, as well as an ``{% else %}`` clause that will be displayed if all\n    previous conditions fail. These clauses are optional.\n\n    ``if`` tags may use ``or``, ``and`` or ``not`` to test a number of\n    variables or to negate a given variable::\n\n        {% if not athlete_list %}\n            There are no athletes.\n        {% endif %}\n\n        {% if athlete_list or coach_list %}\n            There are some athletes or some coaches.\n        {% endif %}\n\n        {% if athlete_list and coach_list %}\n            Both atheletes and coaches are available.\n        {% endif %}\n\n        {% if not athlete_list or coach_list %}\n            There are no athletes, or there are some coaches.\n        {% endif %}\n\n        {% if athlete_list and not coach_list %}\n            There are some athletes and absolutely no coaches.\n        {% endif %}\n\n    Comparison operators are also available, and the use of filters is also\n    allowed, for example::\n\n        {% if articles|length >= 5 %}...{% endif %}\n\n    Arguments and operators _must_ have a space between them, so\n    ``{% if 1>2 %}`` is not a valid if tag.\n\n    All supported operators are: ``or``, ``and``, ``in``, ``not in``\n    ``==`` (or ``=``), ``!=``, ``>``, ``>=``, ``<`` and ``<=``.\n\n    Operator precedence follows Python.\n    ' #NEWLINE# bits = token . split_contents ( ) [ 1 : ] #NEWLINE# condition = TemplateIfParser ( parser , bits ) . parse ( ) #NEWLINE# nodelist = parser . parse ( ( 'elif' , 'else' , 'endif' ) ) #NEWLINE# conditions_nodelists = [ ( condition , nodelist ) ] #NEWLINE# token = parser . next_token ( ) #NEWLINE# while token . contents . startswith ( 'elif' ) : #NEWLINE# #INDENT# bits = token . split_contents ( ) [ 1 : ] #NEWLINE# condition = TemplateIfParser ( parser , bits ) . parse ( ) #NEWLINE# nodelist = parser . parse ( ( 'elif' , 'else' , 'endif' ) ) #NEWLINE# conditions_nodelists . append ( ( condition , nodelist ) ) #NEWLINE# token = parser . next_token ( ) #NEWLINE# #UNINDENT# if ( token . contents == 'else' ) : #NEWLINE# #INDENT# nodelist = parser . parse ( ( 'endif' , ) ) #NEWLINE# conditions_nodelists . append ( ( None , nodelist ) ) #NEWLINE# token = parser . next_token ( ) #NEWLINE# #UNINDENT# assert ( condition . contents == 'endif' ) #NEWLINE# return IfNode ( conditions_nodelists )