Anastasis
Anastasis

Reputation: 729

What is the difference between double curly braces and triple curly braces for Handlebars.js

For instance, you can see {{{body}}} and in the templates, you are able to do something like {{data.page.hero.text}}

Is there any significant difference we should be aware of?

Upvotes: 23

Views: 20927

Answers (2)

Bilal Sipra
Bilal Sipra

Reputation: 523

Handlebars HTML-escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", {{{.

Reference: https://handlebarsjs.com/guide/expressions.html#html-escaping

Upvotes: 28

elenaHristova
elenaHristova

Reputation: 731

Depending on your use case and logic, you may add an option "noEscape" set to true when compiling the template if you want to use {{ }} when {{{ }}} are required to successfully replace the templates. For example: replacing with JSON values.

From the documentation:

var template = Handlebars.compile('{{foo}}', { noEscape: true });

noEscape: Set to true to not HTML escape any content.

Upvotes: 1

Related Questions