When outputting {{user}}
, Handlebars will first retrieve the user
‘s .toString()
value. For plain Object
s, the default result of this is the "[object Object]"
you’re seeing.
To get something more useful, you’ll either want to display a specific property of the object:
{{user.id}}
{{user.name}}
Or, you can use/define a helper to format the object differently:
Handlebars.registerHelper('json', function(context) {
return JSON.stringify(context);
});
myView = new myView({
user : {{{json user}}} // note triple brackets to disable HTML encoding
});