solspace / craft-express-forms

Express Forms for Craft: Intuitive and lightweight form builder that gets the job done but doesn’t get in your way.
https://docs.solspace.com/craft/express-forms/v2/
Other
13 stars 4 forks source link

Malformed email notification error when using extends #75

Closed ruudvdboom closed 2 years ago

ruudvdboom commented 3 years ago

Express form throws an error when using extends in the email notification templates. The notifications do work, but the error appears when editing the form (i think because the files are loaded in the select fields in the field editor)

Error message

Malformed email notification template "_layout.twig" in "/****/templates/_inc/express_forms/notifications/_layout.twig" [] []

Example template

---
name: 'Default Admin Notification'
description: ''
fromName: '{{ craft.app.systemSettings.getSettings("email").fromName }}'
fromEmail: '{{ craft.app.systemSettings.getSettings("email").fromEmail }}'
replyTo:
cc:
bcc:
subject: 'New submission from your {{ form.name }} form'
includeAttachments: false
---

{% extends '_inc/express_forms/notifications/_layout.twig' %}

{% block body %}
    <table>
        {% for field in form.fields %}
            <tr>
                <td>{{ field.label|t }}: </td>
                <td>{{ field.valueAsString|raw }}</td>
            </tr>
        {% endfor %}
    </table>
{% endblock %}
kjmartens commented 2 years ago

Sorry for the long delay @ruudvdboom. This is likely because you are loading an "irregular" template file (the layout one) inside of a directory that Express Forms assumes are all individual email notification templates. To be clear, you can use layout templates, but they should be located outside of the designated /express_forms/notifications/ directory (assuming this is the directory you have set). 🙂

ruudvdboom commented 2 years ago

No problem! We placed the templates inside a folder which fixes the problem. You could consider to exclude underscore files in your plugin.

kjmartens commented 2 years ago

Thanks, we'll make a note about that. 🙂