Using Drupal 9.1.3 : Webform 6.0.0
I have 4 composite address elements in a webform that may or may not be filled, depending on the user’s other selections within the form.
I can use the default email Body format, selecting the checkbox: Exclude empty elements, but this outputs a list of the Element Title, followed by the Element data.
I would like to display the output using twig markup, with a custom title on the left and the element data on the right as below:
Title |
Data |
Address |
123 The Street |
|
The Town |
|
County, Post Code |
Using the webforms debug submission when testing the form it displays the address: element as null when the form is submitted without any data in the address element of the form.
I have used the code below to check for the null attribute.
{% if webform_token('(webform_submission:values:address)', webform_submission, (), options) == '' %}
<div>Address Element is EMPTY using the '' test</div>
{% elseif webform_token('(webform_submission:values:address)', webform_submission, (), options) == null %}
<div>Address Element is EMPTY using the null test</div>
{% else %}
<div>Address Element is EMPTY</div>
{% endif %}
This always displays ‘Address Element is EMPTY’
If I test other Webform elements that results in a empty string eg. ” when no data is entered, the above twig code works with the correct (webform_submission:values:element) and I can elimate the empty custom Title and element using twig code.