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) %}
or
{% if webform_token('[webform_submission:values:join_a_file:value]', webform_submission) is not null %}
or
{% if webform_token('[webform_submission:values:join_a_file]', webform_submission) is not null %}
and none of them work.
Can anybody help me get the proper syntax for what I'm trying to do? Thanks!
Comment | File | Size | Author |
---|---|---|---|
#2 | webform.webform.issue_2969437.yml | 4.06 KB | jrockowitz |
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe issue is that tokens are no longer being cleared when no value is being stored in the database.
When no file is uploaded the call to
webform_token('[webform_submission:values:join_a_file:value]', webform_submission)
returns the original token which is[webform_submission:values:join_a_file:value]
.The trick/solution is to add a clear attribute to the token by changing
[webform_submission:values:join_a_file:value]
to[webform_submission:values:join_a_file:value:clear]
.The attached webform renders FILE UPLOADED or NO FILE UPLOADED using...
@see #2920199: Stop clearing missing tokens
BTW, for general support questions, can you please post them to https://drupal.stackexchange.com/questions/tagged/webforms.
Comment #3
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedComment #4
a_godin CreditAttribution: a_godin commentedThank you very much for your answer, that solved it for me.
And I posted my question here as a last resort ... I had posted the same question on drupal stackexchange ( https://drupal.stackexchange.com/questions/260143/how-to-test-the-existe... ) and on the Drupal forum ( https://www.drupal.org/forum/support/theme-development/2018-04-09/how-to... ) but did not get an answer that solved the problem. I will update both with your solution.
Thanks again!
Comment #5
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedNo problem. Thanks for reposting the solution.
Comment #7
AswathyAjish CreditAttribution: AswathyAjish commentedThe above solution worked for me. Thanks.
{% if webform_token('[webform_submission:values:file:clear]', webform_submission) %}
FILE UPLOADED
{% else %}
NO FILE UPLOADED
{% endif %}