在Mustache.js中将文本作为HTML [英] Text as HTML in Mustache.js

查看:156
本文介绍了在Mustache.js中将文本作为HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JavaScript中有这样的数组:

I have an array like this in JavaScript:

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

现在当我在我的Mustache模板中使用它时,它会显示text as:

Now when I use this in my Mustache template it displays the text as:

<p>my html text</p>

我只想把它作为html,如:

I just want to have it as html, like:

my html text

-

我使用的模板是这样的:

The template I use is something like this:

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


推荐答案

如果要输出html,请使用三重花括号。来自文档的 {{{html}}}

use triple curly braces if you want to output html. {{{html}}}


默认情况下,所有变量都是HTML转义的。如果要渲染未转义的HTML,请使用三重胡须:{{{name}}}。你也可以用& unescape变量。

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/

这篇关于在Mustache.js中将文本作为HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆