O'Reilly logo
  • Patrick S thinks this is interesting:

View-specific helpers

While defining helpers globally is nice because they are available to every view that's rendered, sometimes you might only need to define a helper for use within a single view. In this case, you can include the helper right with the ViewModel itself when calling res.render(), as shown in the following code:

var viewModel = {
  name: 'Jason',
helpers: {
    timeago: function(timestamp) {
   return 'a long time ago!';
res.render('index', viewModel); 


Cover of Web Development with MongoDB and Node.js


Handlebars - view specific helpers