javascript - Handlebars 显示 html 标签而不是将其视为 html 标签

标签 javascript jquery html asp.net-mvc handlebars.js

我有 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/

相关文章:

javascript - fabric js 作为 ES6 在 Chrome 中的导入不起作用

javascript - 键盘可访问的网络下拉菜单?

javascript - 以编程方式设置选择(多个)元素值

html - 无法使用for循环从Windows批处理脚本编写html

javascript - 在 Jquery 中切换元素显示的可靠方法

javascript - 如何引用 `defaultProps` 内的 `defaultProps` ?

javascript - 拖放 html 元素或编辑器

javascript - 按钮的背景颜色不会通过 Tab 键选择而改变

javascript - 如何定位 svg 以及根据选择隐藏和显示 svg

JavaScript自动将切片图片添加到div