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.