GrapesJsEmail.xml 2.48 KB
<?xml version="1.0" encoding="UTF-8"?>
<!--
This software is in the public domain under CC0 1.0 Universal plus a
Grant of Patent License.

To the extent possible under law, the author(s) have dedicated all
copyright and related and neighboring rights to this software to the
public domain worldwide. This software is distributed without any
warranty.

You should have received a copy of the CC0 Public Domain Dedication
along with this software (see the LICENSE.md file). If not, see
<http://creativecommons.org/publicdomain/zero/1.0/>.
-->

<screen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/xml-screen-3.xsd">

    <actions>
        <entity-find-one entity-name="moqui.basic.email.EmailTemplate" value-field="emailTemplate" auto-field-map="[emailTemplateId:emailTemplateId]"/>
        <if condition="!emailTemplate || !emailTemplate.htmlLocation">
            <return error="true" message="Email Template not found"/>
        </if>
        <set field="dataPre" from="ec.resource.getLocationReference(emailTemplate.htmlLocation).getText(emailTemplate.htmlPublishedVersionName)"/>
        <script><![CDATA[
            String location = "template.ftl";

            freemarker.template.Template newTemplate;
            Reader templateReader = null;

            try {
                templateReader = new StringReader(context.dataPre);
                // Use the getFtlConfiguration method from ec.resource.templateRenderers.ftl
                newTemplate = new freemarker.template.Template(location, templateReader, ec.resource.templateRenderers.ftl.getFtlConfiguration());
            } catch (Exception e) {
                throw new org.moqui.BaseArtifactException("Error while initializing template at " + location, e);
            } finally {
                if (templateReader != null) {
                    try { templateReader.close(); }
                    catch (Exception e) { logger.error("Error closing template reader", e); }
                }
            }
            StringWriter sw = new StringWriter()
            try {
                newTemplate.createProcessingEnvironment(ec.contextStack, sw).process();
            } catch (Exception e) { throw new org.moqui.BaseArtifactException("Error rendering template at " + location, e); }
            context.renderedText = sw.toString();
            ]]></script>
    </actions>

    <widgets>
        <render-mode><text type="html"><![CDATA[${renderedText}]]></text></render-mode>
    </widgets>
</screen>