handlebars-lang /handlebars.js

Minimal templating on steroids.

★ 18,692⑂ 2,080👁 433⑃ 642● 1,415▤ 3
JavaScriptMITCreated 2010-07-31handlebarsjs.com
Download: v4.7.10v4.7.10 ↓4.7.102026-10-05
+0
Daily
18,692
stars
2,080
forks
433
watchers
642
prs
1,415
issues
3
releases

README

Handlebars.js

Handlebars provides the power necessary to let you build semantic templates effectively with no frustration.
Handlebars is largely compatible with Mustache templates. In most cases it is possible to swap out Mustache with Handlebars and continue using your current templates.

Checkout the official Handlebars docs site at
handlebarsjs.com and try our live demo.

 Installing

See our installation documentation.

 Usage

In general, the syntax of Handlebars.js templates is a superset
of Mustache templates. For basic syntax, check out the Mustache
manpage.

Once you have a template, use the Handlebars.compile method to compile
the template into a function. The generated function takes a context
argument, which will be used to render the template.

js
var source =
  'Hello, my name is {{name}}. I am from {{hometown}}. I have ' +
  '{{kids.length}} kids:' +
  '{{kids}}{{name}} is {{age}}{{/kids}}';
var template = Handlebars.compile(source);

var data = {
  name: 'Alan',
  hometown: 'Somewhere, TX',
  kids: [
    { name: 'Jimmy', age: '12' },
    { name: 'Sally', age: '4' },
  ],
};
var result = template(data);

// Would render:
// Hello, my name is Alan. I am from Somewhere, TX. I have 2 kids:
// 
//   Jimmy is 12
//   Sally is 4
// 


Full documentation and more examples are at handlebarsjs.com.

 Precompiling Templates

Handlebars allows templates to be precompiled and included as javascript code rather than the handlebars template allowing for faster startup time. Full details are located here.

 Differences Between Handlebars.js and Mustache

Handlebars.js adds a couple of additional features to make writing
templates easier and also changes a tiny detail of how partials work.

- Nested Paths
- Helpers
- Block Expressions
- Literal Values
- Delimited Comments

Block expressions have the same syntax as mustache sections but should not be confused with one another. Sections are akin to an implicit each or with statement depending on the input data and helpers are explicit pieces of code that are free to implement whatever behavior they like. The mustache spec defines the exact behavior of sections. In the case of name conflicts, helpers are given priority.

 Compatibility

There are a few Mustache behaviors that Handlebars does not implement.

- Handlebars deviates from Mustache slightly in that it does not perform recursive lookup by default. The compile time compat flag must be set to enable this functionality. Users should note that there is a performance cost for enabling this flag. The exact cost varies by template, but it's recommended that performance sensitive operations should avoid this mode and instead opt for explicit path references.
- The optional Mustache-style lambdas are not supported. Instead Handlebars provides its own lambda resolution that follows the behaviors of helpers.
- Handlebars does not allow space between the opening {{ and a command character such as , / or . The command character must immediately follow 

Top issues

Discussions

Latest release

v4.7.10 v4.7.10 2026-10-05
- security: Sanitize the source map URL when minifying - f37c599
- security: Iterate lazily in each and strip whitespace in linear time - 812c226
- security: Escape <!-- and <script in precompiled output - 609d1b1 GHSA-xw65-4hp5-5hc7
- security: Don't trust special properties on context data - ceec388 GHSA-p8wg-vrv2-v86f
- security: Only compile partials that are template strings - c28ee7a
- security: Only dispatch known node types in the Compiler and Visitor - 7d501a5
- security: Validate AST values in the compiler instead of the parser - 703fdcc GHSA-8r5x-fm3f-whwj
- Clarify that --ro

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON