Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django-like templates system for Java? [closed]

I'm looking for the templates engine for Java with syntax like in Django templates or Twig (PHP). Does it exists?

Update: The target is to have same templates files for different languages.

<html>
{{head}}
{{ var|escape }}
{{body}}
</html>

can be rendered from python (Django) code as well as from PHP, using Twig. I'm looking for Java solution.

Any other templates system available in Java, PHP and python is suitable.

like image 284
S2201 Avatar asked Jun 07 '10 15:06

S2201


3 Answers

I've developed Jtwig. You could give a try. It's being used in some projects with success. It's easy to setup with a nice integration with spring webmvc.

Just include the dependency using maven or a similar system.

<dependency>   <groupId>com.lyncode</groupId>   <artifactId>jtwig-spring</artifactId>   <version>2.0.3</version> </dependency> 

And configure the view resolver bean to return the Jtwig one.

@Bean public ViewResolver viewResolver() {     JtwigViewResolver viewResolver = new JtwigViewResolver();     viewResolver.setPrefix("/WEB-INF/views/");     viewResolver.setSuffix(".twig");     return viewResolver; } 

Or, if you use xml base configurations:

<bean id="viewResolver" class="com.lyncode.jtwig.mvc.JtwigViewResolver">   <property name="prefix" value="/WEB-INF/views/"/>   <property name="suffix" value=".twig"/> </bean> 
like image 77
João Melo Avatar answered Oct 02 '22 03:10

João Melo


  • http://www.jangod.org/ (There is now also https://github.com/HubSpot/jinjava)
  • run django via jython on jvm
  • use http://mustache.github.com/
like image 31
Intracer Avatar answered Oct 02 '22 01:10

Intracer


If you want the same templates for different languages, you might take a look at Clearsilver.

Clearsilver is a language-neutral template engine which helps separate presentation from code by inserting a language-neutral hierarchial data format (HDF) between your code and templates. Think of HDF like XML, but much simpler.

It's is used for many high-traffic websites, including Yahoo! Groups, Gmail Static HTML, orkut.com, wunderground.com, and others. Implementation languages used with it include C/C++, Python, Java, Ruby, PHP, C#, and others. The Python framework also includes a Page-Class dispatcher and simple ORM which is a bit Ruby-On-Rails like in that it makes mapping between database tables, HDF, and templates take very little code.

The main Clearsilver implementation is in C with language-specific wrappers. There is also a 100% java implementation made by Google and open-sourced called JSilver.

http://www.clearsilver.net/

http://code.google.com/p/jsilver/

like image 36
David Jeske Avatar answered Oct 02 '22 03:10

David Jeske