Skip to content

Instantly share code, notes, and snippets.

@megclaypool
Last active May 31, 2024 09:12
Show Gist options
  • Save megclaypool/cdc8ad3d2e44b3f1c3fa962205bdab2c to your computer and use it in GitHub Desktop.
Save megclaypool/cdc8ad3d2e44b3f1c3fa962205bdab2c to your computer and use it in GitHub Desktop.
[How to include Drupal 8 & 9 webform values in confirmation etc emails]

In the email subject use:

  • [webform_submission:values:YOUR_FIELD_KEY].
    If you don't want a label to appear, you need to add :no_label
  • [webform_submission:values:YOUR_FIELD_KEY:no_label]
  • If the value is a field in a fieldset, use [webform_submission:values:YOUR_FIELDSET_FORM_KEY:YOUR_FIELD_KEY].
    (For more details, look at the webform tokens)

In the Email handler's custom Twig template:

  • {{ data.YOUR_FIELD_KEY }}
    (For more info, look at the "HELP USING TWIG") section.

If you'd like to output a nice list of labels and values for all filled-out fields, you can use the following:

{% for key, value in data %} 
  {% if webform_token('[webform_submission:values:' ~ key ~ ']', webform_submission) %}
    {{ webform_token('[webform:element:' ~ key ~ ']', webform) }}: {{ webform_token('[webform_submission:values:' ~ key ~ ']', webform_submission) }}
  {% endif %}
{% endfor %}

with formatting:

<p><b><u>Submitted Data</u></b></p>
{% for key, value in data %} 
  {% if webform_token('[webform_submission:values:' ~ key ~ ']', webform_submission) %}
    <p><b>{{ webform_token('[webform:element:' ~ key ~ ']', webform) }}</b>: <br>
    {{ webform_token('[webform_submission:values:' ~ key ~ ']', webform_submission) }}</p>
  {% endif %}
{% endfor %}

References:

@elenakarlovalbbd
Copy link

Hi! Is it possible to somehow render data in blocks by wizard pages?
I mean,
wizard page title

  • submission values for this wizard page in a table
    next wizard page title
  • submission values for the next wizard page in a table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment