跨Java和Javascript模板语言?

跨Java和Javascript模板语言?

问题描述:

似乎有很多Java模板语言(例如JSP,JSTL,Freemarker,Velocity等)和Javascript(例如Mustache,Ext的XTemplate,Jquery模板......)但是有一个哪个都有实现?

There seem to be a lot of template languages for both Java (e.g. JSP, JSTL, Freemarker, Velocity, ...) and for Javascript (e.g. Mustache, Ext's XTemplate, Jquery templates, ...) but is there one which have an implementation for both?

理想情况下,我希望能够拥有一个可以在服务器或客户端评估的模板而不需要太多麻烦切换。

Ideally I'd like to be able to have an template which can be evaluated either on the server or on the client side without too much hassle switching over.

Google Closure / Soy模板

Web Templating Languages的Wikipedia页面揭示了另一个: Casper

这两种解决方案都不使用直接在JS或Java中评估的通用模板文件。在对客户端进行评估之前,必须首先将模板编译为中间JS。 (对于Closure,这很容易用 ant 和一个包含 SoyToJsSrcCompiler.jar 命令行工具。不确定关于Casper。)

Both these solutions don't use a common template file which is directly evaluated in JS or Java. The template must first be compiled into an intermediate JS before evaluation on the client. (For Closure, this is fairly easy to do with ant and an included SoyToJsSrcCompiler.jar command line tool. Not sure about with Casper.)

编辑:另一种可能性是 Mustache 需要编译模板。

Another possibility is Mustache, which does not require templates to be compiled.