945aff82 by acetousk

Get the correct version in the email

1 parent 88448cae
...@@ -17,11 +17,34 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -17,11 +17,34 @@ along with this software (see the LICENSE.md file). If not, see
17 17
18 <actions> 18 <actions>
19 <entity-find-one entity-name="moqui.basic.email.EmailTemplate" value-field="emailTemplate" auto-field-map="[emailTemplateId:emailTemplateId]"/> 19 <entity-find-one entity-name="moqui.basic.email.EmailTemplate" value-field="emailTemplate" auto-field-map="[emailTemplateId:emailTemplateId]"/>
20 <if condition="!emailTemplate"> 20 <if condition="!emailTemplate || !emailTemplate.htmlLocation">
21 <return error="true" message="Email Template not found"/> 21 <return error="true" message="Email Template not found"/>
22 </if> 22 </if>
23 <set field="dataPre" from="ec.resource.getLocationReference(emailTemplate.htmlLocation).getText(emailTemplate.htmlPublishedVersionName)"/>
24 <script><![CDATA[
25 String location = "template.ftl";
23 26
24 <set field="renderedText" from="ec.resource.template(emailTemplate.htmlLocation, 'ftl')"/> 27 freemarker.template.Template newTemplate;
28 Reader templateReader = null;
29
30 try {
31 templateReader = new StringReader(context.dataPre);
32 // Use the getFtlConfiguration method from ec.resource.templateRenderers.ftl
33 newTemplate = new freemarker.template.Template(location, templateReader, ec.resource.templateRenderers.ftl.getFtlConfiguration());
34 } catch (Exception e) {
35 throw new org.moqui.BaseArtifactException("Error while initializing template at " + location, e);
36 } finally {
37 if (templateReader != null) {
38 try { templateReader.close(); }
39 catch (Exception e) { logger.error("Error closing template reader", e); }
40 }
41 }
42 StringWriter sw = new StringWriter()
43 try {
44 newTemplate.createProcessingEnvironment(ec.contextStack, sw).process();
45 } catch (Exception e) { throw new org.moqui.BaseArtifactException("Error rendering template at " + location, e); }
46 context.renderedText = sw.toString();
47 ]]></script>
25 </actions> 48 </actions>
26 49
27 <widgets> 50 <widgets>
......