Super helpers
In Meteor, you will quickly find yourself repeating helpers among templates for simple things such as formatting. We can prevent repetition by creating a global dictionary of functions—this is what we call a super helper. To do this, we are going to tap into Meteor's rendering engine—Blaze.
It is important to understand that Blaze is deeply integrated with Spacebars, and Spacebars is Meteor's updated version of HandlebarsJS. HandlebarsJS is a JavaScript templating engine that enables the use of helpers and components on the frontend using {{}}
. This legacy means that Spacebars has a lot of the HandlebarsJS functionality. So, much of the documentation found in HandlebarsJS applies to Meteor helpers as well.
Defining a Blaze helper
Meteor exposes the Template.registerHelper
function to create global helpers. Let's create something to help us format money:
# /_globals/client/formatters.coffee
Template.registerHelper "format_money", (value) ->
if _.isNumber value
"$#{(value...