1

I need to email multiple addresses from a composite element in a webform. Using a Computed Twig element with this code:

{% for m in data.member_information %}
{{ m.email }}
{% endfor %}

The email addresses are listed line by line in Results.

[email protected]
[email protected]

I guess that means they're in an array, but I'm not sure. Here's the configuration of the composite element:

id: member_information
uuid: 591d262f-998d-4ade-8e40-56d8119592dd
status: true
label: 'Member Information'
elements: |
  first_name:
    '#type': textfield
    '#required': true
    '#title': 'First Name'
  middle_name:
    '#type': textfield
    '#title': 'Middle Name'
  last_name:
    '#type': textfield
    '#required': true
    '#title': 'Last Name'
  phone:
    '#type': tel
    '#required': true
    '#title': Phone
  cell_phone:
    '#type': tel
    '#title': 'Cell Phone'
  email:
    '#type': email
    '#required': true
    '#title': Email
description: 'Group Nomination composite.'
langcode: en
dependencies: {  }

The configuration uses the webform composite module.

In the handler, the email addresses need to be a comma separated list in the To email field, like this:

[email protected],[email protected]

I've tried

{% for m in data.member_information %}
{{ m.email|join(',') }}
{% endfor %}

In Results, email addresses are still listed line by line.

How do I convert the line separated list to a comma separated string in the twig template?

1
  • How sure are you this is an array? It could be a line break. What is the configuration of the composite element?
    – cilefen
    Jul 14, 2023 at 22:54

1 Answer 1

2

You don't have an array of email addresses, you have an array of composite field items.

So loop over the field items, build the array of emails

{% set emails = [] %}
{% for m in data.member_information %}
  {% set emails = emails|merge([m.email]) %}
{% endfor %}

and then output the joined array:

{{ emails|join(',') }}
1
  • Works perfectly. Thank you.
    – esod
    Jul 15, 2023 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.