I have a webform with a Document File field. In my twig email template, I want to test if that field is empty. For text area fields for example, this syntax works :

{% if webform_token('[webform_submission:values:question_text_area:value]', webform_submission) %} <br> <table> <tr> <th>Questions</th> </tr> <tr> <td>{{ webform_token('[webform_submission:values:question_text_area:value]', webform_submission) }}</td> </tr> </table> {% endif %}

But for a Document File field, the same syntax does not work, meaning that if no file is uploaded, that part of my template is still printed.

I tried

{% if webform_token('[webform_submission:values:join_a_file:value]', webform_submission) %}


{% if webform_token('[webform_submission:values:join_a_file:value]', webform_submission) is not null %}


{% if webform_token('[webform_submission:values:join_a_file]', webform_submission) is not null %}

and none of them work.

Does anybody know the proper syntax for what I'm trying to do? Thanks!


The solution is to do this

{% if webform_token('[webform_submission:values:file:clear]', webform_submission) %} FILE UPLOADED {% else %} NO FILE UPLOADED {% endif %}

Solution given first here : https://www.drupal.org/project/webform/issues/2969437

| improve this answer | |

The problem is the not operator. You can do like this:

{% if webform_token('[webform_submission:values:join_a_file:value]', webform_submission) is null %}

Then you can add an else statement that runs if it is not empty.

| improve this answer | |
  • Thank you for answering. I tried what you suggested but still no luck. – agodin Apr 19 '18 at 22:09
  • What if you remove the is null and just checks if it is true, you could also try the is defined keyword. If this do not work then it might be the webform token that is wrong. – user72672 Apr 20 '18 at 1:59
  • Tried the "defined" keyword and got an error : 'The "defined" test only works with simple variables in blablabla'. I will ask on the Webform Issues page on Drupal. Thanks! – agodin Apr 25 '18 at 21:22

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.