I'm a newbie in nodejs and i'm learning to use handlebars to render a website.
Here is my routing (inside index.js)
app.get('/house', function (req, res) {
var houses = [
{
name: "House a",
address: "Address a",
price: "Price a"
},
{
name: "House b",
address: "Address b",
price: "Price b"
},
{
name: "House c",
address: "Address c",
price: "Price c"
}
]
res.render('house', houses);
})
Here is my house.handlebars
<div class="row">
{{#each houses}}
<div class="col-md-3 col-lg-3">
<p>Name: {{name}}</p>
<p>Address: {{address}}</p>
<p>Price: {{price}}</p>
</div>
{{/each}}
</div>
The problem is when i go to http://localhost:3000/house, the page is all white and render nothing. I inspected the site and notice that everything inside {{each houses}} and {{/each}} disappear. I'm wondering what are the problems here. Many thanks
Your object structure is incorrect. try this:
res.render('house', {houses: houses});