Use of brackets bug in Swig template for node.js

268 views Asked by At

As it seems swig template is not able to do some basic stuff such as having two conditions within brackets inside an if statement, I was wondering how you guys will deal with this without having to duplicate code:

{% if( absence.approved and absence.rejected) or (demo.demo and demo.test) %} 
      whatever
{% endif %}

Right now that breaks the view because Swig doesn't support it...

2

There are 2 answers

0
Rahul Pal On

remove the brackets and it should work fine

{% if absence.approved and absence.rejected or demo.demo and demo.test %} 

whatever

{% endif %}
1
Paul Armstrong On

Works fine if you fix the location of your first parenthesis:

> var swig = require('swig')
> swig.render('{% if( foo and bar) or (baz and bop) %}yep{% endif %}');
Error: Unexpected tag "if( foo and bar) or (baz and bop)" on line 1.
> swig.render('{% if (foo and bar) or (baz and bop) %}yep{% endif %}');
''
>