Reputation: 1797
I can not figure how to display data passed to handlabars view. here is my route.js file, which passes object to view.
var session = require('express-session');
exports.admin = function(req, res){
db.query("SELECT * FROM users", function(err, result, field){
if(err) throw err;
console.log(result);
console.log(typeof result);
res.render('page', {user: result});
});
};
and here is my page.hbs file(view)
<table>
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>View Details</th>
</thead>
<tbody>
{{#each user}}
<td>{{this}}</td>
{{/each}}
</tbody>
Upvotes: 3
Views: 2081
Reputation: 2600
<tbody>
{{#each user}}
<tr>
<td>{{firstname}}</td>
<td>{{lastname}}</td>
<td>{{details}}</td>
</tr>
{{/each}}
</tbody>
firstname, lastname, details are the properties of each user object
Upvotes: 2