2013-03-07 122 views
5

我们正在使用Mustachejs转换旧CMS。 内容的主体包含了一些HTML元素:Mustachejs将html标记呈现为html

<strong>Mickey Mouse</strong> is a funny animal cartoon character created in 1928 by Walt Disney. 

我们我们运用价值Mustachejs像{{说明}}

渲染输出是

<strong>Mickey Mouse</strong> is a funny animal cartoon character 
created in 1928 by Walt Disney. 

Mustachejs字面上显示数据库中的值。

我们如何让Mustachejs将html标记呈现为html?

所需的结果

米老鼠是沃尔特·迪斯尼于1928年创建了一个有趣的动物卡通人物 。

回答

19

这不是字面上显示值,因为它在数据库中,它的编码。它实际上是输出

&lt;strong&gt;Mickey Mouse&lt;/strong&gt; 

使用{{{three_braces}}}使Mustache呈现而不使用html编码字符串。 {{{Description}}}

+0

完美...很简单。爱慕胡子JS到目前为止。 – 2013-03-07 14:06:20

+1

请注意,当您在用户输入中使用三个大括号时,在呈现之前应仔细清理它。 – bobthecow 2013-03-07 14:33:29

+0

而且你绝对应该*无论什么* @ bobthecow关于小胡子的说法! – Popnoodles 2013-03-07 18:03:11