Skip to main content

Expressions

Handlebars expressions are the basic unit of a Handlebars template. They are some content enclosed by double curly braces {{...}} You can use them alone in a {{mustache}}, pass them to a Handlebars helper, or use them as values in hash arguments.

In this example, we have two expressions inside an HTML p tag

<p>{{firstname}} {{lastname}}</p>

If the below input object is applied to the template

{
"firstname": "Yehuda",
"lastname": "Katz"
}

Expressions are compiled to produce the output as follows:

<p>Yehuda Katz</p>

Escaping​

Handlebars expects that the target format is HTML, so it will automatically escape any HTML characters in the output.

{
"firstname": "Yehuda & Sisters",
"lastname": "Katz"
}

Will produce the following output:

<p>Yehuda &amp; Sisters Katz</p>

The ampersand is escaped to &amp; as required by HTML.

If you want to output the raw HTML, you can use the triple mustache {{{...}}}

<p><![CDATA[
{{{firstname}}} {{{lastname}}}
]]></p>

Will produce the following output:

<p><![CDATA[
Yehuda & Sisters Katz
]]></p>