Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
luke-nehemedia opened this issue Jul 11, 2024 · 2 comments

Comments

@luke-nehemedia
Copy link

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

  • Multi-page form: No
  • Submission Method: Ajax
  • Client-side Validation: Yes
  • Custom Form Templates: Yes

Craft CMS version

Craft Pro 4.10.4

Plugin version

2.1.20

Multi-site?

Yes

Additional context

No response

@engram-design
Copy link
Member

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
Copy link
Author

luke-nehemedia commented Jul 12, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants