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

有帮助吗?

解决方案

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

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

See also:

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top