node.js - nodeJS + Swig template passing variable to javascript -


is there way using express + swig template nodejs pass variables server side client side javascript? know can done in jade i'd rather stick template engine more closely resembles html. guys!

ok assume configure express consolidate.swig if not please read link (http://tinyurl.com/kcs8kvy). didn't find direct way pass variable values client javascript have found workaround.

for instance you're sending object, in route @ express:

app.get("/", function(req, res){   var myuser = { name: "obama" };   res.render("index", {user: myuser}); }); 

then in index.html file can create script tag:

<html>

<body> <script>   var username = "{{user.name}}"; </script>  <script src="whatever.js"></script> </body> 

</html>

and in whatever.js file username variable available correct value. hope you.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -