data.foo = ["a","b","c"]
{% if data.foo and data.foo.length > 0 %}
controller.foo = {{ data.foo }}
{% endif %}
controller.foo = a,b,c
whereas I wanted to get
controller.foo = ["a","b","c"]
is there any way of telling nunjucks to export the variable value as a json string ?
function JSONStringify(data) {
return JSON.stringify(data)
}
data.JSONStringify = JSONStringify
nj.render(templateName,data,function(err,res) {
cb(err,res)
})
}
{% if data.foo and data.foo.length > 0 %}
controller.foo = {{ JSONStringify(data.foo) }}
{% endif %}