如何忽略 Mustache 模板中的车把表达式?

How to ignore a handlebars expression in Mustache templates?

我已经多次阅读有关模板化的 Mustache 规范,但我不知道如何忽略 handlebars 表达式。我有一个必须呈现 {{value}} 的 mustache 模板,但 mustache 似乎无法逃脱车把。

http://mustache.github.io/mustache.5.html

例如;

example.mustache

<p>This would {{value}} not be changed</p>

我需要在模板输出中打印上面的 {{value}}

这是一个代码片段,展示了我的尝试。

console.log(Mustache.render('Example of {{value}} what I want ignored',{}));
console.log(Mustache.render('Does not work \{\{value\}\}',{}));
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/3.0.3/mustache.js"></script>

我敢肯定这很简单,但我想不通。

这是满足您要求的解决方法,

var dataObject ={}
dataObject.openbrace = '{{';
dataObject.closebrace = '}}';
dataObject.value = 'Your Value';

    console.log(Mustache.render('Example of {{value}} what I want ignored',{}));
    console.log(Mustache.render('Does not work {{openbrace}}{{value}}{{closebrace}}',dataObject ));

或者你可以使用一些分隔符 Mustache.render('Example of {{=<% "{{" %>=}}{<% value %>}<%={{ "}}" }}=%>', routeObj);

我花了 疯狂 很长时间才弄清楚官方 转义车把的方法,它隐藏在一些源代码中评论。

<p>This would {{ "{{" }}value{{ "}}" }} not be changed</p>

不用说,没有真正的方法可以逃脱它们。 技巧 只是发出车把的字符串值。