问题
So, I've got a fairly straightforward handlebars template which an element that looks like this:
<div>
{{include_text}}
</div>
I am trying to insert some html like:
<table>
....lots of table stuff
</table>
When I use the table with the template, what I get looks like:
<div>
<table>
... lots of table stuff
</table>
</div>
and I want:
<div>
<table>
....lots of table stuff
</table>
</div>
Is this possible? If so, how?
回答1:
Handlebars (and Mustache) escape the double Mustaches.
Use triple ones
{{{include_text}}}
From the official GitHub:
By default, the {{expression}} syntax will escape its contents. This helps to protect you against accidental XSS problems caused by malicious data passed from the server as JSON.
To explicitly not escape the contents, use the triple-mustache ({{{}}}).
Note, the escaping isn't "just there", if your output contains user-entered data, not-escaping might enable them to perform XSS.
来源:https://stackoverflow.com/questions/16863965/handlebarsjs-templates-using-html-content