Mustache: Globally disable html escaping?

Christopher Klewes picture Christopher Klewes · Apr 7, 2014 · Viewed 14k times · Source

Is there a way how I can (without modifying the sources of mustache) disable the HTML escaping? I'm using mustache for other things and dont want to have the following entities escaped.

var entityMap = {
  "&": "&",
  "<": "&lt;",
  ">": "&gt;",
  '"': '&quot;',
  "'": '&#39;',
  "/": '&#x2F;'
};

Given a template like foo '{{bar}}' and a view { bar : 1 }will produce foo &#39;1&#39.

Answer

Andrew Newby picture Andrew Newby · Apr 7, 2014

If you are trying to just NOT HTML escape some strings, you just do {{{xx}}} instead of {{xx}}

As per:

http://mustache.github.io/mustache.5.html

So if you had a string that consisted of:

test => Q & A

Calling with:

{{ test }}

would give you:

Q &amp; A

..but calling with:

{{{ test }}} or {{ &test }}

Would give you just:

q & a