Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning blocktrans output to variable

I would like to assign the output of a blocktrans block to a template variable.

You can do that using the trans tag like so:

{% trans "Some text to translate" as foo %}

However you can't do the same with a blocktrans tag. I don't see it in the documentation that you can do this.

like image 441
LeeMobile Avatar asked Feb 25 '13 18:02

LeeMobile


1 Answers

Django 1.9 added an asvar component to blocktrans. An example from the docs:

{% blocktrans asvar the_title %}The title is {{ title }}.{% endblocktrans %}
<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.

like image 156
Tim Tisdall Avatar answered Oct 12 '22 07:10

Tim Tisdall