helpers /  Overview

Overview

Documentation for the helpers in the handlebars-helpers library. If you find any errors or have suggestions for improvement please let us know. Contributors are welcome!

Get the helper generator → for Assemble.

Highlighted features unique to Assemble

  • File globbing using minimatch patterns. See the {{glob}} helper for an example.
  • Access to native assemble options.
  • Helper options can be defined using Assemble task or target options. For example, in the Gruntfile for your project you can define indentation level for the {{prettify}} helper like this: assemble: { options: { prettify: { indent: 2 }}}
  • Ability to render either markdown or HTML conditionally, based on the file extension of the generated file.
  • Many more features...

Contributing

The simplest way to contribute is to show your support by starring the project!

Using Custom Helpers

Contributors welcome! Please consider adding your helpers to this library!

Handlebars makes it pretty easy to add custom helpers. Just register your function into Handlebars with the Handlebars.registerHelper method and that helper will be available to any template you compile afterwards.

Handlebars Helpers Basics

Handlebars.js ships with some built-in helpers, such as {{#each}}, {{#if}} and {{#unless}}. Here is how helpers work:

  • A Handlebars helper call is a simple identifier, followed by zero or more parameters (separated by space).
  • Each parameter is a Handlebars expression.
  • Handlebars helpers can be accessed from any context in a template.

Handlebars.js is currently the default template library for assemble.

Helper types

Handlebars allows two different kinds of helpers:

  • Expression helpers are basically regular functions that take the name of the helper and the helper function as arguments. Once an expression helper is registered, it can be called anywhere in your templates, then Handlebars takes the expression's return value and writes it into the template.
  • Block helpers There are a few block helpers included by default with Handlebars, {{#each}}, {{#if}} and {{#unless}}. Custom block helpers are registered the same way as exptression helpers, but the difference is that Handlebars will pass the contents of the block compiled into a function to the helper.

Learn about adding custom helpers to Assemble.

Thanks to Dan Harper and Elving Rodriquez! Many of these helpers originated in the following repos:


See the template for this page →

Find an error? Let us know →