def smart_if(parser, token):
 bits = token.split_contents()[1:]
 var = TemplateIfParser(parser, bits).parse()
 nodelist_true = parser.parse(('else', 'endif'))
 token = parser.next_token()
 if (token.contents == 'else'):
  nodelist_false = parser.parse(('endif',))
  parser.delete_first_token()
 else:
  nodelist_false = None
 return SmartIfNode(var, nodelist_true, nodelist_false)

def smart_if ( parser , token ) : bits = token . split_contents ( ) [ 1 : ] var = TemplateIfParser ( parser , bits ) . parse ( ) nodelist_true = parser . parse ( ( 'else' , 'endif' ) ) token = parser . next_token ( ) if ( token . contents == 'else' ) : nodelist_false = parser . parse ( ( 'endif' , ) ) parser . delete_first_token ( ) else : nodelist_false = None return SmartIfNode ( var , nodelist_true , nodelist_false )
a smarter {% if %} tag for django templates .