胡须模板字符串内部呈现为HTML [英] Mustache template string inside render as HTML
问题描述
我正在使用胡须来呈现模板。
我有这个json对象:
{
title:Foo bar,
content:< p> Html here< / p>,
footer:footer content here
}
我有一个胡须模板,例如:
< div id =box>
< div id =title> {{title}}< / div>
< div id =content> {{content}}< / div>
< div id =footer> {{footer}}< / div>
< / div>
我的问题是变量内容中的html没有被渲染,而是被打印到屏幕。
我看到(在非视图源窗口中):< p> Html here< / p>
,我只想看看是否查看了页面源代码。
我怎样才能解决这个问题:当我将一个字符串传递给胡须模板时,HTML里面会呈现出来?我打电话给mustache.render(templates.all,data);就像我呼吁胡子一样。 胡须文档:
默认情况下,所有变量都是HTML转义的。如果您想要返回
非转义的HTML,请使用三重胡须:{{{name}}}。
只需在模板中使用例如 {{{content}}}
:
< div id =box>
< div id =title> {{title}}< / div>
< div id =content> {{{content}}}< / div>
< div id =footer> {{footer}}< / div>
< / div>
I am using Mustache to render templates.
I have this json object:
{
title: "Foo bar",
content: "<p> Html here </p>",
footer: "footer content here"
}
I have a Mustache template like:
<div id="box">
<div id="title"> {{title}} </div>
<div id="content"> {{content}} </div>
<div id="footer"> {{footer}} </div>
</div>
My problem is that the html within the variable content is not getting rendered but instead is just getting printed to the screen.
I see (in non-view source window): <p> Html here </p>
, where I would only want to see that if I viewed the page source.
How can I fix such that when I pass in a string to a mustache template the HTML inside gets rendered? I am calling mustache.render(templates.all,data); as my call to mustache.
From the Mustache documentation:
All variables are HTML escaped by default. If you want to return unescaped HTML, use the triple mustache: {{{name}}}.
So you just have to use eg.{{{content}}}
in your template:
<div id="box">
<div id="title"> {{title}} </div>
<div id="content"> {{{content}}} </div>
<div id="footer"> {{footer}} </div>
</div>
这篇关于胡须模板字符串内部呈现为HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!