Search code examples
node.jsexpressswig

How to set JSON object in variable using swig node js?


I want to set a JSON object in client side javascript using swig. I tried with json filter of swig but it just print JSON object not assign. <script type="text/javascript"> var bootstrap = "{{locals.bootstrap | json}}"</script> as we know in Javascript this bootstrap variable is globally accessible in whole the application. but I am not able to set JSON object. I tried this var bootstrap = "{{locals.bootstrap}}" refer link . but its for just any property not for json object, its just set "[object,object]" in bootstrap not json object. I tried with json filter of swig refered link , but not get succeed.


Solution

  • Try

    var bootstrap = "{{bootstrap | json | safe}}"