Opened 15 years ago

Closed 12 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: dev
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

Description

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 by Russell Keith-Magee, 15 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Matt McClanahan, 13 years ago

Severity: Normal
Type: Bug

comment:3 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 by Aymeric Augustin, 12 years ago

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