What is the correct syntax to test if a file has been uploaded in a webform in a twig email template?

For a text area, {% if webform_token('[webform_submission:values:question_text_area:value]', webform_submission) %} works fine but to test if a file has been uploaded, {% if webform_token('[webform_submission:values:join_a_file:value]', webform_submission) %} does not work.

Also, when there's a file uploaded, I want to display in the email only the title of the file ... {{ webform_token('[webform_submission:values:join_a_file:delta:format:value]', webform_submission) }} works but it outputs a link to that file. Is it possible to just have the text of the file name?


1 Answer 1


That is a great question.

Getting just the filename is not currently supported but you can pull the file's URL using [webform_submission:values:join_a_file:delta:format:url]

The current list of supported formats for uploaded files is here. I created a ticket to add machine name to element submission display formats so that this information is exposed to site builder.

If you need just the file name, please create a new ticket in the Webform module's issue queue.

  • I created a ticket to add a filename format to managed file elements drupal.org/project/webform/issues/2959088#comment-12560276
    – jrockowitz
    Commented Apr 6, 2018 at 9:44
  • Thank you for creating the ticket ... I was going to wait to see if I could extract the filename from the url but even when I put [webform_submission:values:join_a_file:delta:format:url] in my email twig template, the output is always a link with the filename. I should have specified my field is a Document File ... maybe it doesn't work with this filetype?
    – agodin
    Commented Apr 6, 2018 at 19:29
  • Also, I tried creating a conditionnal email that would be enabled only if my file field was empty to solve my problem of testing if a file has been uploaded in a twig email template ... is "Empty" the correct Trigger/Value for that use case? I tried it but the email is not sent when the condition is met.
    – agodin
    Commented Apr 6, 2018 at 19:42
  • The [webform_submission:values:join_a_file:delta:forma:name] token is now supported in the latest dev release. If you are finding other bugs please create a ticket in the Webform module's issue queue. drupal.org/project/issues/webform?version=8.x
    – jrockowitz
    Commented Apr 7, 2018 at 8:50
  • Sorry about the extra questions, I'll check the issue queue to see if that's been reported. If not, I'll create a ticket.
    – agodin
    Commented Apr 9, 2018 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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