Search code examples
javacuba-platform

CUBA-Platform + EmailInfo - How to specify FTL template path under WEB-INF?


I have email.ftl under modules/portal/web/WEB-INF/templates/email/ (a subfolder I created). In my controller code, I have my EmailInfo declaration, and I want to specify the path to email.ftl.

Looking at this tutorial, I see the EmailInfo declaration is this:

EmailInfo emailInfo = new EmailInfo(
            "john.doe@company.com,jane.roe@company.com", 
            newsItem.getCaption(),
            null,
            "com/company/demo/templates/news_item.txt",
            Collections.singletonMap("newsItem", newsItem)
    );

I notice the relative path leading to news_item.txt starts from com/ which leads me to believe that the root of the path starts from the "src" folder of the module the controller is in (my controller is in app-portal, so in my case, portal/src). Since my template is under web/ and not src/, I specified my path as so:

EmailInfo emailInfo = new EmailInfo("email@email.com", "Email Template", null, "../web/WEB-INF/templates/email/email.ftl", null, null);[/pre]

However, it didn't work, as an error was thrown:

java.lang.IllegalArgumentException: Could not find template by path: ../web/WEB-INF/templates/email/email.ftl

So my question is, how to specify this file path to go under a different subfolder, specifically "modules/portal/web"?

Thanks, Mingle

==X-posted from CUBA-Platform forum==


Solution

  • Thanks to Yuriy Artamonov on CUBA-Platform for answering:

    Unfortunately, you cannot store email templates in portal / web modules, since they are processed on a middleware. I recommend that you put them into core module src folder. In fact, "/" means CLASS-PATH root, not the folder.

    Templates are loaded by Emailer using Resources interface which loads resources using the following rules: https://doc.cuba-platform.com/manual-6.5/resources.html

    I put email.ftl under modules/core/src/com/example/test/email/email.ftl and specified the path of /com/example/test/email/email.ftl and it worked.