【问题标题】:Use Mustache with PlayFramework将 Mustache 与 PlayFramework 一起使用
【发布时间】:2013-01-27 16:54:09
【问题描述】:

如何使用 play-mustache 模块 (http://www.playframework.org/modules/mustache-head/home) 作为服务器端的默认模板渲染引擎?

按照文档的方式,似乎我每次需要渲染模板时都必须调用 mustache.print。这没有多大意义,因为我不想将每个 mustache 模板包装在一个 groovy 模板中,这将调用并呈现它。我希望这发生在幕后,即当一个控制器动作渲染时,渲染器应该使用 Mustache 而不是 groovy。

【问题讨论】:

    标签: playframework mustache playframework-1.x


    【解决方案1】:

    看来你可以打电话了

    MustacheSession session = MustachePlugin.session();
    String html = session.toHtml("yourTemplate.html",data);
    renderHtml(html);
    

    https://github.com/murz/play-mustache/blob/master/app/play/modules/mustache/MustacheTags.java#L35

    我不能说我理解 Mustache 中的 Scope 类是如何工作的,但这里有一个链接: where data is Map used by the mustache Scope 类 http://grepcode.com/file/repo1.maven.org/maven2/com.github.spullara.mustache.java/core/0.6/com/sampullara/mustache/Scope.java

    【讨论】:

      猜你喜欢
      • 2013-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-11
      • 1970-01-01
      • 2016-07-23
      • 1970-01-01
      相关资源
      最近更新 更多