How to use Django translable variable (trans) in if statement template

I ran into a problem in django. The following is a snippet of code:

{% if pageName != 'My page Name' %}
  .....{{ then this }}

Now this is great for English. Now that I have translated my application into another language, I have pageNamealso changed in accordance with this language. Thus, the above logic does not work because it is hardcoded in English

So, I should try to implement the logic with the translated version 'My page Name'. But I can not use it directly in if, for example:

{% if pageName != trans 'My page Name' %} 

So I thought about saving the translated version in another variable, and then checking it with this variable:

{%blocktrans%} "My page Name" {{myvar}} {%endblocktrans%}
{% if pageName != myvar %}

But this also does not work myvartakes value "My page Name", not the translated version.

, . .

+4
1

trans template,

{% trans "My page Name" as myvar %} 
{% if pageName != myvar %}
...

.

+5

Source: https://habr.com/ru/post/1529153/


All Articles