I need to pass the following into an included template via the Django include tag:
{% include 'btn.html' with
btn_text='Hi '|add:first_name|add:' - Verify Email Now'
btn_url=verify_url
%}
Therefore I can dissect the entire question in two parts:
A. Is it possible to have first_name
added into the string in another, more elegant, manner at template level ?
B. I need to have the string translated at template level - is it possible?
Ie what I intend to do (but is not syntactically correct) is the below:
{% include 'btn.html' with
btn_text=
{% blocktrans first_name as first_name %}
Hi {{first_name}} - Verify Email Now
{% endblocktrans %}
btn_url=verify_url
%}
I found the solution in this post :
Here is the given example:
{% trans "Load more promotions" as promotions %}
{% include "a_dir/stuff.html" with text=promotions %}
To format the string, you could do that in the view and pass it in the context:
context = {'btn_text': 'Hi {0} - Verify Email Now'.format(first_name)}
return HttpResponse(context=context)
For translation of text, have a look at the following link:
https://docs.djangoproject.com/en/1.2/topics/i18n/internationalization/#trans-template-tag
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.