I'm on D9, theming a webform email.

I'm currently overriding the twig file, instead of using the configuration of the body in the email hanlder, because there are various conditional logic I've to check - e.g. if interface language is en print element a otherwise element b.

To create the required markup, I need to get the info of the elements: for example, for select elements, I need the label and the text of the option selected, not the raw value.

However, I can't find them using the webform_submission, as it seems to contain only the raw data put by the user.

For now, I've find this way to get the info I need, but I'd like to know if there's a more direct\better way to get them:


{% set submission_data =webform_submission.getData %}
{% set webform = handler.getWebform %}
{% set my_element_test = webform.getElementDecoded('element_id') %}
{% set option_label_test = my_element['#options']['options_id'] %}

{# todo print the markup for all elements #}

1 Answer 1


For anyone needing this, doing this in the twig works:

{% set webform = webform_submission.getWebform %}
{% set webform_element = webform.getElement(key) %}
{% set submission_data =webform_submission.getData %}

//value = value of the specific element inside submission_data
{% if webform_element['#options'] is defined %}
  {{ webform_element['#options'][value] }}
{% else %}
  {{ value }}
{% endif %}

Doing a bit of code-diving, I've seen that WebformOptionsHelper::getOptionText() - called at some point by the code ran by Webform tokens' function - does a bit more complex logic to get the values, but at least for my case the above is sufficient.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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