Opened 6 years ago

Closed 2 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

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 Changed 5 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 4 years ago by mattmcc

  • Severity set to Normal
  • Type set to Bug

comment:3 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 2 years ago by aaugustin

  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.
Back to Top