I have a nodejs application. I'm using handlebars js as a view engine. I'm trying to access one element from nested object that I'm passing to the hbs view.
router.get('/view_users/:id', function (req, res, next) {
Users.find({ userId: req.params.id }, function (err, users) {
if (err) {
throw err;
} else {
res.render('view_user', { title: 'Users', user: users});
}
})
});
and then in the view_user I would like to access only one users.name.<p>{{users.name}}</p> (Without built-in helpers such as #each because it will return me a list of all users)
I tried {{user.name}}, {{name}}, and {{{user.name}}} but it returns me undefined.
Users is the mongoose Schema.
How can I do it? Thanks.
{{title}}work?console.log(JSON.stringify(users));right before your call to therendermethod?