Buy Handlebars swag on DevSwag!
Handlebars expressions are the basic unit of a Handlebars template. You can use them alone in a {{mustache}}, pass them to a Handlebars helper, or use them as values in hash arguments.

Basic Usage

The simplest Handlebars expression is a simple identifier:
This expression means "look up the title property in the current context". Block helpers may manipulate the current context, but they do not change the basic meaning of an expression.
Actually, it means "look for a helper named title, then do the above", but we'll get to that soon enough.
Handlebars expressions can also be dot-separated paths.
This expression means "look up the article property in the current context. Then look up the title property in the result".
Handlebars also supports a deprecated / syntax, so you could write the above template as:
Identifiers may be any unicode character except for the following:
Whitespace ! " # % & ' ( ) * + , . / ; < = > @ [ \ ] ^ ` { | } ~
To reference a property that is not a valid identifier, you can use segment-literal notation, [:
{{#each articles.[10].[#comments]}}
In the example above, the template will treat the each parameter roughly eqivalent to this javascript: articles[10]['#comments']
You may not include a closing ] in a path-literal, but all other characters are fair game.
Handlebars HTML-escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", {{{


A Handlebars helper call is a simple identifier, followed by zero or more parameters (separated by space). Each parameter is a Handlebars expression.
{{{link story}}}
In this case, link is the name of a Handlebars helper, and story is a parameter to the helper. Handlebars evaluates parameters in exactly the same way described above in "Basic Usage".
Handlebars.registerHelper('link', function(object) {
  return new Handlebars.SafeString(
    "<a href='" + object.url + "'>" + object.text + "</a>"
When returning HTML from a helper, you should return a Handlebars SafeString if you don't want it to be escaped by default.
You can also pass a simple String as a parameter to Handlebars helpers.
{{{link "See more..." story.url}}}
In this case, Handlebars will pass the link helper two parameters: the String "See more..." and the result of evaluating story.url in the current context.
Handlebars.registerHelper('link', function(text, url) {
  return new Handlebars.SafeString(
    "<a href='" + url + "'>" + text + "</a>"
You could use the exact same helper with dynamic text based on the value of story.text:
{{{link story.text story.url}}}
Handlebars helpers can also receive an optional sequence of key-value pairs as their final parameter (referred to as hash arguments in the documentation):
{{{link "See more..." href=story.url class="story"}}}
The keys in hash arguments must each be simple identifiers, and the values are Handlebars expressions. This means that values can be simple identifiers, paths, or Strings.
Handlebars.registerHelper('link', function(text, options) {
  var attrs = [];

  for(var prop in options.hash) {
    attrs.push(prop + '="' + options.hash[prop] + '"');

  return new Handlebars.SafeString(
    "<a " + attrs.join(" ") + ">" + text + "</a>"
Handlebars provides additional metadata, such as Hash arguments, to helpers as a final parameter.
Handlebars also offers a mechanism for invoking a helper with a block of the template. Block helpers can then invoke that block zero or more times with any context it chooses.
Learn More: Block Helpers


Handlebars offers support for subexpressions, which allows you to invoke multiple helpers within a single mustache, and pass in the results of inner helper invocations as arguments to outer helpers. Subexpressions are delimited by parentheses.
{{outer-helper (inner-helper 'abc') 'def'}}
In this case, inner-helper will get invoked with the string argument 'abc', and whatever the inner-helper function returns will get passed in as the first argument to outer-helper (and 'def' will get passed passed in as the second argument to outer-helper.
Fork me on GitHub