When using Thymeleaf with Spring, we can use ${T(full.package.name.ClassName).staticMethod(args)} to call a static method of an utility class. Without Spring, the syntax seems to be ${@full.package.name.ClassName@staticMethd(args)}. For FreeMarker, only java.lang.System is exposed so you have to register manually class hashes using root.put("statics", BeansWrapper.getDefaultInstance().getStaticModels()); or change the security level to EXPOSE_ALL.
In order to provide a better use experience for developers that don't really need to know how Thymeleaf or Freemarker work, Ogham should handle an abstraction to declare some utility functions with some alias.
For example, user could configure an alias (Dates) to call org.example.util.DateUtil.format(args). In templates you could then use it like ${Dates.format(args)} for all template engines.
FreeMarker allows to register TemplateHashModel so alias would work easily.
Need to check how to add this feature with Thymeleaf.
When using Thymeleaf with Spring, we can use
${T(full.package.name.ClassName).staticMethod(args)}
to call a static method of an utility class. Without Spring, the syntax seems to be${@full.package.name.ClassName@staticMethd(args)}
. For FreeMarker, onlyjava.lang.System
is exposed so you have to register manually class hashes usingroot.put("statics", BeansWrapper.getDefaultInstance().getStaticModels());
or change the security level toEXPOSE_ALL
.In order to provide a better use experience for developers that don't really need to know how Thymeleaf or Freemarker work, Ogham should handle an abstraction to declare some utility functions with some alias.
For example, user could configure an alias (Dates) to call
org.example.util.DateUtil.format(args)
. In templates you could then use it like${Dates.format(args)}
for all template engines.FreeMarker allows to register
TemplateHashModel
so alias would work easily. Need to check how to add this feature with Thymeleaf.