将html插入到句柄模板中而不会转义 [英] Insert html in a handlebar template without escaping
本文介绍了将html插入到句柄模板中而不会转义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种方法可以将带有html标签的字符串插入到句柄模板中,而不会使标签在输出字符串中转义?
template.js:
< p> {{content}}< / p>
使用模板
HBS.template({content:< i> test< / i> 123})
实际结果:
< p>< i& gt; test& lt; / I和GT; 123 LT; / p为H.
预期结果:
< p为H.;< I>试验< / I> 123 LT; / p为H.
解决方案
试试像
< p> {{content}}}< / p>
我得到了官方参考来支持我的回答:
lockquote
{{表达}}
。 如果您的
不想让Handlebars转义一个值,请使用三重藏, {{{
。
Is there a way to insert a string with html tags into a handlebars template without getting the tags escaped in the outcoming string?
template.js:
<p>{{content}}</p>
use the template
HBS.template({content: "<i>test</i> 123"})
actual outcome:
<p><i>test</i> 123</p>
expected result:
<p><i>test</i> 123</p>
解决方案
Try like
<p>{{{content}}}</p>
I got the official reference to support my answer:
Handlebars HTML-escapes values returned by a
{{expression}}
. If you don't want Handlebars to escape a value, use the "triple-stash",{{{
.
这篇关于将html插入到句柄模板中而不会转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文