Syntax Reference¶
This page covers all supported Handlebars template syntax.
Variable Interpolation¶
Use double curly braces to output a value:
Values are output as-is by default. When auto_escape=True is enabled, values are HTML-escaped.
Triple-stache and & always output unescaped content regardless of the auto_escape setting:
Paths¶
Dot Notation¶
Access nested properties with dots:
Slash Notation¶
Slashes work the same as dots:
this Keyword¶
Refer to the current context:
Parent Scope¶
Access parent contexts with ../:
Multiple levels work too: {{../../grandparent}}.
@data Variables¶
Special variables prefixed with @:
| Variable | Description |
|---|---|
@root |
The root context |
@index |
Current array index (in #each) |
@key |
Current object key (in #each) |
@first |
true for the first iteration |
@last |
true for the last iteration |
Literals¶
Use literal values directly in expressions:
{{helper "string"}}
{{helper 'single quoted'}}
{{helper 42}}
{{helper 3.14}}
{{helper true}}
{{helper false}}
{{helper null}}
{{helper undefined}}
Comments¶
Comments are stripped from output:
Whitespace Control¶
Add ~ to strip whitespace on that side of a tag:
{{~expression}} {{!-- strips whitespace before --}}
{{expression~}} {{!-- strips whitespace after --}}
{{~expression~}} {{!-- strips both sides --}}
This works on all tag types including blocks:
Block Helpers¶
Block helpers wrap a section of the template:
Inverse / Else¶
Use {{else}} or {{^}} for the inverse block:
{{#if condition}}
Truthy
{{else}}
Falsy
{{/if}}
{{#if condition}}
Truthy
{{^}}
Falsy (same as else)
{{/if}}
Chained Else¶
Chain conditions with {{else if}}:
Block Parameters¶
Capture block values with as |param|:
{{#each items as |item index|}}
{{index}}: {{item.name}}
{{/each}}
{{#with person as |p|}}
{{p.name}}
{{/with}}
Hash Arguments¶
Pass named arguments to helpers:
Subexpressions¶
Nest helper calls as arguments using parentheses:
Raw Blocks¶
Raw blocks pass content through without processing:
The content between raw block tags is output as-is.
Escaped Delimiters¶
To output literal {{, escape with a backslash:
This renders as {{not a variable}}.