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.
dataset/ETHPy150Open skorokithakis/django-annoying/annoying/templatetags/smart_if.py/smart_if