我有 Handlebars 模板,其中填充了一些复杂的消息(带有图像、粗体文本等 html 内容...)。我不知道如何强制这个库将我的消息文本视为带有一些文本内容的有效 html 节点。
我正在做这样的事情:
<div class="title">
<strong>
<a href="/Home/Post/{{this.MESSAGE_ID}}">{{this.MESSAGE_TITLE}}</a>
</strong>
</div>
其中 {{this.MESSAGE_TITLE}} 可以是正确的 html 内容。
最佳答案
尝试在 {{
或 {{{
> 后使用 &
{{&this.MESSAGE_TITLE}}
或
{{{this.MESSAGE_TITLE}}}
来自mustache website Handlebars 源自...
All variables are HTML escaped by default. If you want to return unescaped HTML, use the triple mustache: {{{name}}}.
You can also use & to unescape a variable: {{& name}}. This may be useful when changing delimiters
关于javascript - Handlebars 显示 html 标签而不是将其视为 html 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22846907/