#NEWLINE# @ register . tag #NEWLINE# def firstof( parser , token ) : #NEWLINE# #INDENT# '\n    Outputs the first variable passed that is not False, without escaping.\n\n    Outputs nothing if all the passed variables are False.\n\n    Sample usage::\n\n        {% firstof var1 var2 var3 %}\n\n    This is equivalent to::\n\n        {% if var1 %}\n            {{ var1|safe }}\n        {% else %}{% if var2 %}\n            {{ var2|safe }}\n        {% else %}{% if var3 %}\n            {{ var3|safe }}\n        {% endif %}{% endif %}{% endif %}\n\n    but obviously much cleaner!\n\n    You can also use a literal string as a fallback value in case all\n    passed variables are False::\n\n        {% firstof var1 var2 var3 "fallback value" %}\n\n    If you want to escape the output, use a filter tag::\n\n        {% filter force_escape %}\n            {% firstof var1 var2 var3 "fallback value" %}\n        {% endfilter %}\n\n    ' #NEWLINE# bits = token . split_contents ( ) [ 1 : ] #NEWLINE# if ( len ( bits ) < 1 ) : #NEWLINE# #INDENT# raise TemplateSyntaxError ( "'firstof' statement requires at least one argument" ) #NEWLINE# #UNINDENT# return FirstOfNode ( [ parser . compile_filter ( parser ) for bit in bits ] )