Text as HTML in Mustache.js

Saif Bechan picture Saif Bechan · Oct 11, 2012 · Viewed 22.4k times · Source

I have an array like this in JavaScript:

[name: "myname", text: "<p>my html text</p>"]

Now when I use this in my Mustache template it displays the text as:

<p>my html text</p>

I just want to have it as html, like:

my html text

--

The template I use is something like this:

<div>
    {{name}}
    {{html}}
</div>

Answer

Mark picture Mark · Oct 11, 2012

use triple curly braces if you want to output html. {{{html}}}

from the docs:

All variables are HTML-escaped by default. If you want to render unescaped HTML, use the triple mustache: {{{name}}}. You can also use & to unescape a variable.

https://github.com/janl/mustache.js/