Opened 9 years ago

Closed 6 years ago

#12332 closed Bug (duplicate)

{% blocktrans with value as variable %} syntax cannot parse literal values passed through filters

Reported by: Alun Bestor Owned by: nobody
Component: Template system Version: master
Severity: Normal Keywords: blocktrans i18n
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


As a contrived example:

{% blocktrans with "String Literal"|lower as lowercase_string %}Here is a lowercase string: {{ lowercase_string }}{% endblocktrans %}

This example will fail in Django 1.1 and 1.2 trunk with:

TemplateSyntaxError: variable bindings in 'blocktrans' must be 'with value as variable'

The example will be parsed successfully if the filter is omitted, or if the filtered value is a context variable instead of a literal (e.g. string_var|lower).

One workaround for the parsing problem would be to use the following code:

{% with "String Literal"|lower as lowercase_string %}
{% blocktrans with lowercase_string as lowercase_string %}Here is a lowercase string: {{ lowercase_string }}{% endblocktrans %}
{‰ endwith %}

(In the contrived example it is of course unnecessary to use the lower filter on a literal value; the actual case came up with a custom filter which processes a value differently depending on active settings.)

Change History (5)

comment:1 Changed 9 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

comment:2 Changed 8 years ago by Matt McClanahan

Severity: Normal
Type: Bug

comment:3 Changed 7 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 Changed 7 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 Changed 6 years ago by Aymeric Augustin

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top