I recommend you to take a look Rythm template engine. Rythm is a static typed template engine for Java. You need to declare all the template parameters using @args
directive. And the consequence is you get a type safe template with clear interface.
You can play with the online interactive fiddle site for Rythm at http://fiddle.rythmengine.org/
Disclaim: I am the author of Rythm template engine
Updates to answer @user2043423's concern about attribute checking
So first every rythm template is compiled into a java class, thus it's absolutely typesafe. second, because it is typesafe, it does check if the attributes exists in your Java class or not. For example you have a rythm template defined as:
@args Employee employee
Hello @employee.getFistName()
You will get a compilation error when you run the template because there is a typo in @employee.getFistName()
, and once you fixed that to @employee.getFirstName()
the rythm will go ahead to render the template
In case you want to check if the template argument employee has been passed to the template or not, use @if
:
@args Employee employee
@ifNot(employee) {
@return
}
Hello @employee.getFirstName()!
See http://rythmengine.org/doc/directive.md#if for more about @if
directive