[Solved]-Assigning blocktrans output to variable


Django 1.9 added an asvar component to blocktrans (now called blocktranslate). An example from the docs:

{% blocktranslate asvar the_title %}The title is {{ title }}.{% endblocktranslate %}
<title>{{ the_title }}</title>
<meta name="description" content="{{ the_title }}">

Unfortunately, it seems that before that was added you needed some other way of doing it.


That isn’t possible with the blocktrans tag.

However, you could use this captureas templatetag to capture the output of blocktrans.

{% captureas trans_value %}
    {% blocktrans %}
        This has some stuff in it which will be translated {{ foo }}.
    {% endblocktrans %}
{% endcaptureas %}

{{ trans_value }}

Leave a comment