ozer
ozer

Reputation: 345

Node.js listing objects in views

How do I list my posts in node.js?

server.js

app.set('view engine', 'html');
app.engine('html', hbs.__express);
app.set('views', __dirname + '/views');
app.use(express.static(__dirname + '/public'));


app.get('/', function(req, res) {
    connection.query('SELECT * FROM wp_posts', function(err, rows, fields) {
        res.render('index', {posts: rows});
    });

});

client, index.html:

{{#each post in posts}}
    {{post.title}}
{{/each}}

How does this work, please help guys. I searched but everyone told this with jade or hbs. I want to use standart html render.

Upvotes: 0

Views: 48

Answers (1)

Vadim
Vadim

Reputation: 17957

I suspect your template is wrong. Try:

{{#each posts}}
    {{title}}
{{/each}}

Upvotes: 1

Related Questions