Nunjucks: support `&&` and ` || ` ?

Created on 27 Dec 2015  路  5Comments  路  Source: mozilla/nunjucks

{% if list && list.length>0 %} and {{ someVal || "test"}}

Most helpful comment

The documentation for if (https://mozilla.github.io/nunjucks/templating.html#if) says "It behaves exactly as javascript's if behaves".

All 5 comments

https://github.com/mozilla/nunjucks/issues/344#issuecomment-70645452

We do aim to have as close API/syntax to jinja as much as possible, so adding && || !, although familiar to javascript, would potentially polute and confuse, having multiple ways of doing the same thing.

Agreed, we don't need redundant syntax for things that already exist.

The documentation for if (https://mozilla.github.io/nunjucks/templating.html#if) says "It behaves exactly as javascript's if behaves".

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

// Or Snippet
{% if (VARIABLE == 10) or (VARIABLE == 20) %}
    //
{% endif %}

The documentation for if (https://mozilla.github.io/nunjucks/templating.html#if) says "It behaves exactly as javascript's if behaves".

I was mislead by the document as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gaboesquivel picture gaboesquivel  路  4Comments

boutell picture boutell  路  6Comments

kud picture kud  路  3Comments

dgirgenti picture dgirgenti  路  3Comments

rayalan picture rayalan  路  5Comments