21

I've a context processor which adds objects (i.e. site) to the template context but the value is not rendered inside the {% blocktrans %} template tag. Outside the template tag, the value prints just fine.

<h1>{% trans "About" %} {{ site.domain }}</h1> <!-- works -->

{% blocktrans %}
   {{ site.domain }} <!-- doesn't work -->
{% endblocktrans %}

How do I get the object's attribute / variable to render inside {% blocktrans %}?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Franck
  • 325
  • 3
  • 7

1 Answers1

39

Interpolated variables cannot be dotted expressions - you need something like this:

{% blocktrans with site_domain=site.domain %}{{ site_domain }} is a ...{% endblocktrans %}

See also:

Community
  • 1
  • 1
AdamKG
  • 13,678
  • 3
  • 38
  • 46
  • Should I need to deactivate() previous language? because I used same above tag but still its not translating. – Mohini Jun 18 '15 at 07:09
  • 1
    Just in case anyone's wondering (as I was): If you need to specify multiple variables the syntax is to seperate the definitions with a space. Like so: `{% blocktrans with foo_bar=foo.bar spam_eggs=spam.eggs %}...{% endblocktrans %}` – Owl Surojit Apr 29 '22 at 12:50