Django 1.4 doc says that you can get translated strings into "vars" to be used in different places or to be used as arguments in template tags or filters using the following syntax:
{% trans "String" as my_translated_string %}
<h1>{{ my_translated_string }}</h1>
https://docs.djangoproject.com/en/1.4/topics/i18n/translation/#trans-template-tag
I'm doing it in that way, however the defined var is never rendering the content. Below my template code:
{% extends "default_layout.html" %}
{% load i18n %}
{% trans "My page title" as title %}
{% block meta_title %}{{ title }}{% endblock %}
{% block content %}
<h1>{{ title }}</h1>
{% endblock %}
Of course "title" is being rendered empty in both cases.
Am I missing something ?
Thank you.
As okm
said you need to define the variable within the block in which you want to use it, and the scope of that variable is also within the block:
{% extends "default_layout.html" %}
{% load i18n %}
{% block meta_title %}
{% trans "My page title" as title %}
{{ title }}
{% endblock %}
{% block content %}
{% trans "My page title" as title %}
<h1>{{ title }}</h1>
{% endblock %}
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