This page is not available in every language. Missing translations are disabled in the language selector.

Quick reference

Handlebars.js Cheatsheet

A quick reference guide for Handlebars.js: expressions, block helpers, custom helper functions, partials, and template rendering.

· Published

Handlebars.js provides semantic templating without logic entanglements, extending Mustache templates.

Syntax & Helpers

Expressions & Interpolation

<p>{{firstname}} {{lastname}}</p>
<p>{{{rawHtmlContent}}}</p>

Built-in Block Helpers

{{#if isActive}}
  <span class="active">Active</span>
{{else}}
  <span class="inactive">Inactive</span>
{{/if}}

{{#each items}}
  <li>{{this}}</li>
{{/each}}

{{#with author}}
  <h2>By {{name}}</h2>
{{/with}}

Custom Helpers

Handlebars.registerHelper('fullName', function (person) {
  return person.firstName + ' ' + person.lastName;
});

Template usage:

<p>{{fullName user}}</p>

References

Related topics