def firstof(*vars):
for var in vars:<EOL><INDENT>if var:<EOL><INDENT>return var<EOL><DEDENT><DEDENT>
Outputs the first variable passed that is not False, without escaping.

Outputs nothing if all the passed variables are False.

Sample usage::

    {% firstof var1 var2 var3 %}

This is equivalent to::

    {% if var1 %}
        {{ var1|safe }}
    {% else %}{% if var2 %}
        {{ var2|safe }}
    {% else %}{% if var3 %}
        {{ var3|safe }}
    {% endif %}{% endif %}{% endif %}

but obviously much cleaner!

You can also use a literal string as a fallback value in case all
passed variables are False::

    {% firstof var1 var2 var3 "fallback value" %}

If you want to escape the output, use a filter tag::

    {% filter force_escape %}
        {% firstof var1 var2 var3 "fallback value" %}
    {% endfilter %}