Context value / variable not rendered inside blocktrans template tag
-
14-11-2019 - |
Question
I've a context processor wich 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 %}
?
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:
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow