@register.tag('if')
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 aehlke/manabi/apps/utils/templatetags/smartif.py/smart_if