verbb / formie

The most user-friendly forms plugin for Craft CMS.
Other
94 stars 70 forks source link

Fields in a group will not be rendered by custom template in email notification #1978

Open luke-nehemedia opened 1 month ago

luke-nehemedia commented 1 month ago

Describe the bug

I created a custom email templated based on the demo one. I customized the output of a couple of fields to make them display the value in a single line instead of new lines. Everything works perfectly, except for the fields that are part of a group. Those fields will ignore the custom template. How can I fix this?

Steps to reproduce

  1. Create new email template with custom fields
  2. Put some fields into a group
  3. Send form

Form settings

Craft CMS version

Craft Pro 4.10.4

Plugin version

2.1.20

Multi-site?

Yes

Additional context

No response

engram-design commented 1 month ago

The Group field template is still going to call field.getEmailHtml which hooks into the custom template you setup for fields, so that does seem odd.

Can you maybe outline what your custom email template templates look like structurally, just so I can compare on my end?

luke-nehemedia commented 1 month ago

My group template is basically the original template, except that I removed the line-breaks since my customer wants a more condensed output.

The whole outline is as following:

anmeldung/index.html Most submissions have an event-id attached to it.

{% set event = craft.calendar.events({id: submission.eventId, siteId: '*'}) %}
{% if event|length %}
    {% set event = event.one() %}
    {% include '_emails/_components/eventInformationen' %}
{% else %}
    {{ contentHtml }}
{% endif %}

In eventInformationen.twig a summary of the event information is saved into the variable eventInfosRender and replaced in the content. {{ contentHtml|replace({'***VeranstaltungsInfos***': eventInfosRender})|raw }}

Within anmeldung/ is a subfolder fields/ with templates for every field-type. Since I have different email templates that use the same field-templates, every file in the field-folder is loading a field-template from a central location. {% extends "_emails/_fields/agree" %}

Those field-templates are basically identical to the demo template, except for the line-breaks are removed.

group.html

    {% if not (renderOptions.hideName ?? false) %}
        <h3>{{ field.name | t('formie') }}</h3>
    {% endif %}

<div style="margin: 1em 0;">
    {% set fields = field.getFieldLayout().getCustomFields() %}
    {% if value.exists() %}
        {% for row in value.all() %}
            {% for field in fields %}
                {% set fieldValue = (row ? row.getFieldValue(field.handle) : field.normalizeValue(null)) %}
                {% set html = field.getEmailHtml(submission, notification, fieldValue, {hideName: true,}) %}
                {% if html %}
                    {% if field.hasLabel %}<strong>{{ field.name | t('formie') }}:</strong> {% endif %}{{ html | raw }}
                {% endif %}
            {% endfor %}
        {% endfor %}
    {% else %}
        <p>{{ notification.getPlaceholder() }}</p>
    {% endif %}
</div>

The system does work, except for the fields within a group.