Question

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 %}?

Était-ce utile?

La solution

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

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

See also:

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top