Score:1

Email multiple addresses from a composite element in a webform

us flag

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?

id flag
How sure are you this is an array? It could be a line break. What is the configuration of the composite element?
Score:2
cn flag

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(',') }}
us flag
Works perfectly. Thank you.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.