c50af2e1 by acetousk

Actually render the data with ftl in memory

1 parent bb08ed19
...@@ -87,10 +87,30 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -87,10 +87,30 @@ along with this software (see the LICENSE.md file). If not, see
87 } 87 }
88 ]]></script> 88 ]]></script>
89 <!-- <log level="warn" message="dataPre is ${dataPre}"/>--> 89 <!-- <log level="warn" message="dataPre is ${dataPre}"/>-->
90 <set field="grapesTempFile" from="grapesJsResource.makeFile(grapesFile?.dbResourceId + '.temp.json')"/> 90 <script><![CDATA[
91 <script>grapesTempFile.putText(dataPre)</script> 91 String location = "template.ftl";
92 <set field="data" from="ec.resource.template(grapesTempFile.location, 'ftl')"/> 92
93 <script>grapesTempFile.delete()</script> 93 freemarker.template.Template newTemplate;
94 Reader templateReader = null;
95
96 try {
97 templateReader = new StringReader(context.dataPre);
98 // Use the getFtlConfiguration method from ec.resource.templateRenderers.ftl
99 newTemplate = new freemarker.template.Template(location, templateReader, ec.resource.templateRenderers.ftl.getFtlConfiguration());
100 } catch (Exception e) {
101 throw new org.moqui.BaseArtifactException("Error while initializing template at " + location, e);
102 } finally {
103 if (templateReader != null) {
104 try { templateReader.close(); }
105 catch (Exception e) { logger.error("Error closing template reader", e); }
106 }
107 }
108 StringWriter sw = new StringWriter()
109 try {
110 newTemplate.createProcessingEnvironment(ec.contextStack, sw).process();
111 } catch (Exception e) { throw new org.moqui.BaseArtifactException("Error rendering template at " + location, e); }
112 context.data = sw.toString();
113 ]]></script>
94 <!-- <log level="warn" message="data is ${data}"/>--> 114 <!-- <log level="warn" message="data is ${data}"/>-->
95 <set field="moquiVars" from="globalGrapeVarList"/> 115 <set field="moquiVars" from="globalGrapeVarList"/>
96 </then> 116 </then>
...@@ -143,10 +163,13 @@ along with this software (see the LICENSE.md file). If not, see ...@@ -143,10 +163,13 @@ along with this software (see the LICENSE.md file). If not, see
143 catch (Exception e) { logger.error("Error closing template reader", e); } 163 catch (Exception e) { logger.error("Error closing template reader", e); }
144 } 164 }
145 } 165 }
146 context.data = newTemplate.toString(); 166 StringWriter sw = new StringWriter()
167 try {
168 newTemplate.createProcessingEnvironment(ec.contextStack, sw).process();
169 } catch (Exception e) { throw new org.moqui.BaseArtifactException("Error rendering template at " + location, e); }
170 context.data = sw.toString();
147 ]]></script> 171 ]]></script>
148 <!-- <set field="data" from="ec.resource.template(grapesTempFile.location, 'ftl')"/>--> 172 <!-- <log level="warn" message="data is ${data}"/>-->
149 <log level="warn" message="data is ${data}"/>
150 <set field="moquiVars" from="globalGrapeVarList"/> 173 <set field="moquiVars" from="globalGrapeVarList"/>
151 </else-if> 174 </else-if>
152 <else> 175 <else>
......