Articles in this section

Whitespace in Handlebars expressions

Be careful with whitespace in and around Handlebars expressions. Stray whitespace at the start of an expression — or before a symbol inside the braces — can cause errors. Write each expression with no leading whitespace, and make sure every opening {{ has a matching closing }}.

Avoid leading and internal whitespace

Write expressions with no space before the opening braces and no space inside them.

Correct:

{{expression}}{{dateFormat}}

Incorrect — note the leading space before {{ and the space inside each set of braces:

{{ expression}}{{ dateFormat}}

Close each expression before starting another

Every {{ must have a matching }}. If you start a second expression before closing the first, the parser reads the second {{ as part of the first expression and returns an error.

In this example, the first expression is never closed, so the second set of opening braces is misread as a new expression:

{{expression {{field}}