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.
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>
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With