FreeMarker templates stored in database?

I followed the development recipe example for sending emails and using the FreeMarker templates to build an HTML email body – and it all works well. Thank you for a well designed email mechanism.

Now I would like to move the FreeMarker templates into the database so they can be updated through my cuba application. This will allow changes to the emails without the need to redeploy.

I have looked at many ways to try this and had no success. Is there a way to provide a template to the EmailInfo object other than a package resource?

Hi,

This is true - currently there is no public API for loading email templates from the database. But you should be able to do it in your project. Look at com.haulmont.cuba.core.app.Emailer class an its processBodyTemplate() method - this is the point where the template is loaded from a resource specified in the EmailInfo. So you should extend the “cuba_Emailer” bean which is implemented by this class, and override the method providing the template contents by your rules.

Thank you - I will investigate that approach. Perhaps you can consider a future enhancement to the API to accept the template as a string. This would allow most any dynamic template retrieval or creation.

You are right. See the linked issue.

:ticket: See the following issue in our bug tracker:

https://youtrack.cuba-platform.com/issue/PL-9318