Index: django/template/defaulttags.py =================================================================== --- django/template/defaulttags.py (revision 11154) +++ django/template/defaulttags.py (working copy) @@ -564,7 +564,7 @@ #@register.tag def firstof(parser, token): """ - Outputs the first variable passed that is not False. + Outputs the first variable passed that is not False, without escaping. Outputs nothing if all the passed variables are False. @@ -575,11 +575,11 @@ This is equivalent to:: {% if var1 %} - {{ var1 }} + {{ var1|safe }} {% else %}{% if var2 %} - {{ var2 }} + {{ var2|safe }} {% else %}{% if var3 %} - {{ var3 }} + {{ var3|safe }} {% endif %}{% endif %}{% endif %} but obviously much cleaner! @@ -589,6 +589,12 @@ {% 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 %} + """ bits = token.split_contents()[1:] if len(bits) < 1: Index: docs/ref/templates/builtins.txt =================================================================== --- docs/ref/templates/builtins.txt (revision 11154) +++ docs/ref/templates/builtins.txt (working copy) @@ -101,6 +101,13 @@ Values enclosed in single (``'``) or double quotes (``"``) are treated as string literals, while values without quotes are treated as template variables. +Note that as cycle is a tag, variables will never be escaped unless you +do it explicitly with a filter tag :: + + {% filter force_escape %} + {% cycle var1 var2 var3 %} + {% endfilter %} + For backwards compatibility, the ``{% cycle %}`` tag supports the much inferior old syntax from previous Django versions. You shouldn't use this in any new projects, but for the sake of the people who are still using it, here's what it @@ -160,9 +167,10 @@ firstof ~~~~~~~ -Outputs the first variable passed that is not False. Outputs nothing if all the -passed variables are False. +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 %} @@ -170,11 +178,11 @@ This is equivalent to:: {% if var1 %} - {{ var1 }} + {{ var1|safe }} {% else %}{% if var2 %} - {{ var2 }} + {{ var2|safe }} {% else %}{% if var3 %} - {{ var3 }} + {{ var3|safe }} {% endif %}{% endif %}{% endif %} You can also use a literal string as a fallback value in case all @@ -182,6 +190,12 @@ {% 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 %} + .. templatetag:: for for