Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to register utility classes to be used in templates #83

Open
aurelien-baudet opened this issue Nov 7, 2019 · 0 comments

Comments

@aurelien-baudet
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant