简体   繁体   English

在Mustache.js中将文本作为HTML

[英]Text as HTML in Mustache.js

I have an array like this in JavaScript: 我在JavaScript中有这样的数组:

[name: "myname", text: "<p>my html text</p>"]

Now when I use this in my Mustache template it displays the text as: 现在,当我在我的Mustache模板中使用它时,它将文本显示为:

<p>my html text</p>

I just want to have it as html, like: 我只想把它作为html,如:

my html text

-- -

The template I use is something like this: 我使用的模板是这样的:

<div>
    {{name}}
    {{html}}
</div>

use triple curly braces if you want to output html. 如果要输出html,请使用三重花括号。 {{{html}}}

from the docs: 来自文档:

All variables are HTML-escaped by default. 默认情况下,所有变量都是HTML转义的。 If you want to render unescaped HTML, use the triple mustache: {{{name}}}. 如果要渲染未转义的HTML,请使用三重胡须:{{{name}}}。 You can also use & to unescape a variable. 您还可以使用&来取消变量。

https://github.com/janl/mustache.js/ https://github.com/janl/mustache.js/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM