javascript - Accessing handlebars variable inside client js file -


i'm generating handlebars view hbs express js framework, , need access variables pass view inside separate javascript file.

for example:

 var foo = {{user.name}} 

obviously code throws error, preferred way of getting hbs variables inside javascript?

currently i'm running ajax request same data. think not wise make request same data...

found solution, seems had put handlebars variable inside string work.

in order pass , object variable created hbs helper:

 hbs.registerhelper('json', function(context) {     return json.stringify(context);  }); 

and in view:

 var currentuser = json.parse('{{{json user}}}'); 

and can access data on client side js.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -