167
votes

Is there a way to insert a string with html tags into a handlebars template without getting the tags escaped in the outcoming string?

template.js:

<p>{{content}}</p>

use the template

HBS.template({content: "<i>test</i> 123"})

actual outcome:

<p>&lt;i&gt;test&lt;/i&gt; 123</p>

expected result:

<p><i>test</i> 123</p>
3

3 Answers

403
votes

Try like

<p>{{{content}}}</p>

official reference:

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

33
votes

In your template you must add triple mustaches like this. <p>{{{content}}}</p>

15
votes

According to Handlebars documentation, http://handlebarsjs.com/expressions.html

Quote from documentation,

If you don't want Handlebars to escape a value, use the "triple-stash", {{{

Pass the raw HTML to Handlebars template and get the raw HTML output by using triple brackets.

{{{foo}}}