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 = { "&": "&", "<": "<", ">": ">", '"': '"', "'": ''', "/": '/' };
Given a template like foo '{{bar}}'
and a view { bar : 1 }
will produce foo '1'
.
A Mustache tag begins with two opening braces ( {{ ) and ends with two closing braces ( }} ). As you might have guessed, the {{ and }} delimiters are where Mustache gets its name from!
Escaping in HTML means, that you are replacing some special characters with others. In HTML it means usally, you replace e. e.g < or > or " or & . These characters have special meanings in HTML. And the text will appear as hello, world.
Mustache is a logic-less template syntax. It can be used for HTML, config files, source code - anything. It works by expanding tags in a template using values provided in a hash or object. We call it "logic-less" because there are no if statements, else clauses, or for loops.
It's actually pretty simple. Mustache offers the possibility to override the escape
function. This allows you to disable the escaping by simply returning the original value.
mustache.escape = function (value) { return value; };
As mentioned by others, you can also use the following notation to disable escaping.
{{{ test }}}
I leave the answer unchanged, since it might be helpful to implement your own sanitizing.
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 & A
..but calling with:
{{{ test }}} or {{ &test }}
Would give you just:
q & a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With