Accessing handlebars variable inside client js file

点点圈 提交于 2019-12-06 20:50:30

Found the solution, seems like i just had to put the handlebars variable inside a string for it to work.

In order to pass and Object to a variable I created hbs helper:

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

and the in my view:

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

and now i can access the data on the client side js.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!