小胡子渲染忽略所有 {{ }}

Mustache Render Ignoring all {{ }}

我正在使用此处的以下基本介绍示例: https://github.com/janl/mustache.js/

我正在使用以下代码:

  var tmp_view = {
    title: "Joe",
    calc: function(){
      return 2+5;
    }   };

  var tmp_output = Mustache.render("{{title}} spends {{calc}}", tmp_view);

但是,在我的浏览器中,我得到的是:

var tmp_output = Mustache.render(" spends ", tmp_view);

呈现 "spends"

编辑:我想我对发生这种情况的原因有了更好的理解,但我不确定如何解决它。

我正在为我的服务器使用 spark 并具有以下内容

get("/foobar", (req, res) -> new ModelAndView("",
        "foobar.mustache"), new MustacheTemplateEngine());

在我的 .mustache 文件中,我发出了一个 JSON 请求,在该 JSON 请求中,我想渲染另一个模板。

你应该尝试 redefine your delimiter 留小胡子。

基于小胡子文档:

Set Delimiter tags start with an equals sign and change the tag delimiters from {{ and }} to custom strings.

Consider the following contrived example:

  • {{ default_tags }} {{=<% %>=}}
  • <% erb_style_tags %> <%={{ }}=%>
  • {{ default_tags_again }} Here we have a list with three items. The first item uses the default tag style, the second uses ERB style as defined by the Set Delimiter tag, and the third returns to the default style after yet another Set Delimiter declaration.

调用{{=<% %>=}}改变{{ }}<% %>