Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which interoperable templating framework for JavaScript and Grails/Java?

I am currently researching templating frameworks that have implementations for both JavaScript and Grails/Java for an upcoming project that will render templates both within a Grails application and on the front end.

The requirements are as follows:

  • implementations in both JavaScript and Grails / Java
  • front-end and back-end rendering produces the same output given the same JSON data
  • straightforward to author and maintain by a team of developers
  • testable on both front-end and back-end
  • can handle nested JSON objects without too much trouble
  • XSS protection on the front-end

So far, I have investigated Mustache which has JavaScript and Java implementations, and Haml which has JavaScript and Grails implementations. (I would link the implementations, but as a new user I am only able to add 2 links.)

I would be grateful for any experience others have had with these, and any recommendations for other frameworks that may fit the above needs.

like image 933
froots101 Avatar asked Feb 08 '11 10:02

froots101


2 Answers

Did you look at Closure Templates? There's also a Grails plug-in. It meets most if not all your requirements.

like image 122
moraes Avatar answered Oct 20 '22 09:10

moraes


I've used both Mustache and Haml at one point or another. If you hadn't mentioned either, I would probably have recommended Mustache as a pure templating solution. Haml is great, but it is more a replacement for authoring html (i.e. you don't write html any more, you write haml). Mustache on the other hand is all about templating

I think either one would be a fine choice. Mustache.js is mature, the java implementation is probably less so, but it has been around for a little while, so you're probably ok in that regard. I am not sure how mature the javascript or grails Haml implementations are.

I'd be leaning towards Mustache if all you're after is templating, it is very good although it takes a little while to get used to the whole {{}} syntax. But if you're attracted to Haml as a replacement for writing HTML it might tip you in that direction.

like image 33
skorks Avatar answered Oct 20 '22 09:10

skorks