- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
无法理解如何转义 { 或 } 符号旁边的表达式 handlebars java templating engine .
我正在使用 Handlebars 模板生成纯文本,所以我不能按照建议使用 HTML ASCII 码的大括号 there .
我需要像 \{{{variable.name}}\}
这样的表达待解析为{variable.value}
.我应该为此创建助手还是有更清洁的方法?
最佳答案
下面是一些逃逸的例子。最后一个方法使用助手转义(当其他方法不可用时)。
$(document).ready(function () {
var context = {
"textexample1" : "hello",
"textexample2" : "<div><b>hello</b></div>",
"textexample3" : "{ 'json' : 'sample }"
};
Handlebars.registerHelper('surroundWithCurlyBraces', function(text) {
var result = '{' + text + '}';
return new Handlebars.SafeString(result);
});
var source = $("#sourceTemplate").html();
var template = Handlebars.compile(source);
var html = template(context);
$("#resultPlaceholder").html(html);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script id="sourceTemplate" type="text/x-handlebars-template">
Simple text : {{textexample1}}<br/>
Html text not escaped : {{textexample2}}<br/>
Html text escaped : {{{textexample2}}}<br/>
Json text : {{textexample3}}<br/>
Non JSON text with surrounding mustaches {} : { {{textexample1}} }<br/>
Non JSON text with surrounding mustaches (no space) : {{{textexample1}}}<br/>
Solution with helper : {{#surroundWithCurlyBraces textexample1}}{{/surroundWithCurlyBraces}}
</script>
<br/>
<div id="resultPlaceholder">
</div>
关于handlebars.js - 转义大括号站在 Handlebars 中的表达旁边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52020784/
前不久,哔哩哔哩(一般常称为 B 站)发布了一篇文章《2021.07.13 我们是这样崩的》,详细回顾了他们在 2021.07.13 晚上全站崩溃约 3 小时的至暗时刻,以及万分紧张的故障定位与恢复过
想象一下这种情况,周围有一些智能手机和计算机,它们的 WiFi 适配器(无线适配器)打开,但没有必要连接到网络。 有没有办法通过 Linux 机器查看 MAC 地址? 任何见解表示赞赏。 最佳答案 断
我无法创建新的 Window Station 来运行我的应用程序 int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { wprintf(L"
在 Conda 环境中安装包后,我想对该包中的代码进行一些更改。 在哪里可以找到包含已安装包的 site-packages 目录? 我有 Anaconda Python 2.7 base 发行版,但找
今天去改了matplotlib的配置。搜索 matplotlibrc 发现我有两个: 查看site-packages 文件夹,我发现很多包的名称中都有波浪号: ~klearn 是 sklearn ,但
我是一名优秀的程序员,十分优秀!