xmlincludefreemarkersmooks

Smooks - Multiple templates in a config file


How can I use #include to add multiple template files to a smooks config file using freemarker template.

 <ftl:freemarker applyOnElement="Response">
  <ftl:template>
  <BODY>
   <C1><#include "template1.ftl"></C1>
   <C2><#include "template2.ftl"></C2>
   ........
  </BODY>       
 </ftl:template>

It's not a duplicate question, as here the #includes are embedded into another template.


Solution

  • Looking at the source code of FreeMarkerTemplateProcessor.java, it seems that you can't use #include in an inline template (inline means that the template is directly embedded into the ftl:template element), as they don't set the TemplateLoader there. But if inside ftl:template there's a path instead (like /com/example/templates/my.ftl), then the template is loaded from there, and can use #include with similar paths (and with relative paths).