Text as HTML in Mustache.js

放肆的年华 提交于 2019-12-03 18:46:58

问题


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>

回答1:


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/



来源:https://stackoverflow.com/questions/12834419/text-as-html-in-mustache-js

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