Handlebars Helpers

Handlebars supports the idea of helpers, which are special custom functions you can write to perform some special logic from within the template during runtime. A great example of a helper would be the date string formatter we've been using. Helpers can be registered globally and made available to every template file, or they can be defined per view and passed to the template on an as needed basis as a part of the ViewModel.

Global helpers

First, let's create a global helper that will be available to every Handlebars template we render. This global helper that you will create will be used to format a timestamp so that it is worded as to how long ago the event occurred. We will use this throughout our application for things such ...

Get Web Development with MongoDB and Node.js now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.