I'm new to javascript and node. 1st:
app.get('/', function(req, res){
articleProvider.findAll(function(error, docs){
res.render('index.jade', { locals: {
title: 'Blog',
articles:docs
}
});
});
});
2nd
app.get('/', function(req, res){
articleProvider.findAll(function(error, docs){
res.render('index.jade', {
title: 'Blog',
articles:docs
}
);
});
});
1st code is from this tutorial http://howtonode.org/express-mongodb, but doesn't work. 2nd code did work, and i just don't know why? Other parts are exactly same.
In earlier versions of Express you needed to put the vars you wanted to make available to your Jade template in the locals field of that parameter to res.render.
That changed in 3.x so that all the fields of that parameter are available to the rendered template as locals.