If ...! true conditional rendering in nunjucks

if...true

conditionals work like a charm like the docs outlined here .

but if i try to do something like:

{% if !posts.length %}
<i>No project posts yet!</i>
{% endif %}

      

I am getting the error:

Template render error: (/home/nak/clones/mf3/views/project.html) [Line 10, Column 9]
 unexpected token: !

      

I worked around this by doing:

{% if posts.length %}
{% else %}
<i>No project posts yet!</i>
{% endif %}

      

Is there a better (correct) way to do this?

+3


source to share


1 answer


I see you have a little roaming dazzler here.

Try using "not" instead of !.

In other words, use NOT, NOT !!



Give it to a friend and notice that in the original section here they are highlighted differently than if this is a keyword.

https://mozilla.github.io/nunjucks/templating.html#raw

Good luck to you.

+13


source







All Articles