Articles in this section

Literal segments and Handlebars identifiers

A Handlebars identifier is the name you use to reference a field in a path expression. An identifier can be any Unicode character except for a set of reserved characters, and a few reserved words are valid only in the first segment of a path. When a field name breaks these rules — for example, it's a number, contains a hyphen, or is a reserved word — use segment-literal bracket notation to reference it.

Invalid identifier characters

A Handlebars identifier can be any Unicode character except the following, which fail validation:

Whitespace ! " # % & ' () * +,. /; < = > @ [ \ ] ^ ` { | } ~

Reserved words

The words true, false, null, and undefined are valid only in the first segment of a path expression. To reference a field with one of these names later in a path, use bracket notation.

Use segment-literal bracket notation

Use segment-literal notation — square brackets ([ ]) — to reference a field name that contains a reserved character, is a number, or is a reserved word:

{{#each articles.[10].[#comments]}}

You can use any character inside the brackets except a closing bracket (]).

Examples

These examples show how to wrap an invalid segment in brackets:

Incorrect Correct Reason
{{array.0.item}} {{array.[0].item}} The segment 0 is a number.
{{array.[0].item-class}} {{array.[0].[item-class]}} The segment item-class contains a hyphen.
{{./true}} {{./[true]}} true is a reserved word used outside the first segment.

For more information, see the Handlebars.js documentation on literal segments.