Handlebarsjs Templates & using html content

ぐ巨炮叔叔 提交于 2019-12-11 03:33:30

问题


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>
&lt;table&gt;
... lots of table stuff
&lt;/table&gt;
</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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!