1

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

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

4

1 回答 1

0

It looks like you could just call

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

I can't say I understand how the Scope class in Mustache works, but here is a link: where data is Map used by the mustache Scope class http://grepcode.com/file/repo1.maven.org/maven2/com.github.spullara.mustache.java/core/0.6/com/sampullara/mustache/Scope.java

于 2013-01-27T23:45:38.457 回答