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.
Asked
Active
Viewed 811 times
1

Community
- 1
- 1

Bharat Bhushan
- 2,077
- 2
- 21
- 34
1 Answers
1
Try
var bootstrap = "{{bootstrap | json | safe}}"

Subin Sebastian
- 10,870
- 3
- 37
- 42
-
No need to use "locals." – Subin Sebastian May 09 '15 at 14:35
-
See meanjs source where user is set as a global variable in app/views/layout.server.view.html – Subin Sebastian May 09 '15 at 14:36
-
– Subin Sebastian May 09 '15 at 14:37
-
same result after removing "locals" – Bharat Bhushan May 09 '15 at 14:39
-
@ subin will you please share the link where from see – Bharat Bhushan May 09 '15 at 14:40
-
Make sure server is restarted after the change – Subin Sebastian May 09 '15 at 14:40
-
Link https://github.com/meanjs/mean/blob/master/app/views/layout.server.view.html – Subin Sebastian May 09 '15 at 14:41
-
the mistake I was doing it to use "{{bootstrap | json | safe}}" in string format. now json is displaying fine but throw an exception unexpected token o. I cross checked my json object it is ok – Bharat Bhushan May 09 '15 at 14:50