Reputation: 1200
Specifically I want to call {% if typeof(myvar) == "boolean" %}
or {% set a = parseInt(myvar) %}
, but now it gives this error:
SyntaxError: Unexpected token !== at Object.Function () at Object.precompile (/home/aidan/Desktop/nodejs/turbo/node_modules/swig/lib/swig.js:465:11) at Object.compile (/home/aidan/Desktop/nodejs/turbo/node_modules/swig/lib/swig.js:560:16) at Function.exports.swig.render (/home/aidan/Desktop/nodejs/turbo/node_modules/consolidate/lib/consolidate.js:246:56) at /home/aidan/Desktop/nodejs/turbo/node_modules/consolidate/lib/consolidate.js:146:25 at /home/aidan/Desktop/nodejs/turbo/node_modules/consolidate/lib/consolidate.js:99:5 at fs.js:266:14 at Object.oncomplete (fs.js:107:15)
Upvotes: 3
Views: 3097
Reputation: 164
You can define a filter and then write a set
statement with the filter applied to the variable. Finally you can use this variable in your if
statement.
E.g.:
swig.setFilter('isObject', function(element) {
return typeof element == "object";
});
Then:
{% set elementIsObject = myvar|isObject %}
{% if elementIsObject %} ... {% endif %}
Hope this helps.
Upvotes: 8