@register.tag(u'if')
def do_if(parser, token):
 bits = token.split_contents()[1:]
 condition = TemplateIfParser(parser, bits).parse()
 nodelist = parser.parse((u'elif', u'else', u'endif'))
 conditions_nodelists = [(condition, nodelist)]
 token = parser.next_token()
 while token.contents.startswith(u'elif'):
  bits = token.split_contents()[1:]
  condition = TemplateIfParser(parser, bits).parse()
  nodelist = parser.parse((u'elif', u'else', u'endif'))
  conditions_nodelists.append((condition, nodelist))
  token = parser.next_token()
 if (token.contents == u'else'):
  nodelist = parser.parse((u'endif',))
  conditions_nodelists.append((None, nodelist))
  token = parser.next_token()
 assert (token.contents == u'endif')
 return IfNode(conditions_nodelists)

@ register . tag ( u'if' ) def do_if ( parser , token ) : bits = token . split_contents ( ) [ 1 : ] condition = TemplateIfParser ( parser , bits ) . parse ( ) nodelist = parser . parse ( ( u'elif' , u'else' , u'endif' ) ) conditions_nodelists = [ ( condition , nodelist ) ] token = parser . next_token ( ) while token . contents . startswith ( u'elif' ) : bits = token . split_contents ( ) [ 1 : ] condition = TemplateIfParser ( parser , bits ) . parse ( ) nodelist = parser . parse ( ( u'elif' , u'else' , u'endif' ) ) conditions_nodelists . append ( ( condition , nodelist ) ) token = parser . next_token ( ) if ( token . contents == u'else' ) : nodelist = parser . parse ( ( u'endif' , ) ) conditions_nodelists . append ( ( None , nodelist ) ) token = parser . next_token ( ) assert ( token . contents == u'endif' ) return IfNode ( conditions_nodelists )
the {% if %} tag evaluates a variable .