Nunjucks: "if" with multiple conditions "and" or "or"

Today, my team assistant was struggling to add a few conditions using the "and" or "or" in the if statement in the Nunjucks template. After a lot of searching, he found the answer, but not on Stackoverflow. I'm not sure if the answer has already been posted somewhere in SO, but decided to post it now to narrow down future searches.

Below is the answer:

+5
source share
1 answer

Answer:

As we know, Nunjucks is inspired by the Jinja2 python template engine, the if statement is similar to it.

// And Snippet {% if (VARIABLE > 10) and (VARIABLE < 20) %} // {% endif %} // Or Snippet {% if (VARIABLE == 10) or (VARIABLE == 20) %} // {% endif %} 

Here it is!!!

Could not find this in the Nunjucks documentation. I find this answer to be useful, as Nunjucks coders tend to look for the Nunjucks keyword, not Jinja.

+10
source

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


All Articles