Nunjucks: ‘if’ with multiple ‘and’ or ‘or’ condition

Answer:

As we know Nunjucks is inspired by Jinja2 python’s 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 %}

Thats it !!!

Couldn’t find this on Nunjucks documentation either. I believe this answer will be helpful as coders working on Nunjucks tend to search with keyword Nunjucks and not with Jinja.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)