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 %}
?
The point of blocktrans is to allow the text around the placeholders to be translated. It won't translate anything inside {{...}} . If you look at the generated .po file, you'll see that the following template code: {% blocktrans %}This is my variable: {{variable}}{% endblocktrans %}
What is the render context? The class RenderContext is automatically created by the graphics service. It is a collection of data that needs to be passed to every Render method. The render context should contain all information required to render an object or to perform a rendering step.
A context is a variable name -> variable value mapping that is passed to a template. Context processors let you specify a number of variables that get set in each context automatically – without you having to specify the variables in each render() call.
Interpolated variables cannot be dotted expressions - you need something like this:
{% blocktrans with site_domain=site.domain %}{{ site_domain }} is a ...{% endblocktrans %}
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With