In my template, sometimes I want to make the translated string passed through upper
filter. For example, I want to display "Related Links" as "RELATED LINKS". However when I tried, e.g:
{% trans "Related links"|upper %}
TemplateSyntaxError
would be thrown. Any suggestions?
Just use:
{% trans "Related links" as rel %}{{ rel|upper }}
This saves the translation temporarily in a variable which then can be used to apply filters on it.
Source: https://docs.djangoproject.com/en/dev/topics/i18n/translation/#trans-template-tag
Since Django 1.10, you can avoid aliases and just use:
{% trans "Related links"|upper %}
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