0

I'm trying to help my father out by building a webform (D8 version) for the 4 theaters his Old Abbey Friends are putting up.

I've made the webform, now i'm setting up an email handler so that people get a confirmation email. Straightforward enough, however, i'm getting lost when using the twig template option of that email handler on following items:

  • how do i check if there's at least one checkbox checked in a checkbox element (containing 4 checkboxes)?
  • how do i check which of the checkboxes is checked in the above element?
  • how do i get the number in a number element that's part of a custom composite? I tried using the data.composite_elementkey.elementkey syntax, but that just shows up blank.

Any feedback much appreciated!

2 Answers 2

0

Alright, after a lot of searching and testing things out i've found the following things to work:

  1. For the checkbox it won't work with the data.element_name syntax (or at least in any variation that tried, and that's a couple dozen). What will work is this: {{ webform_token('[webform_submission:values:ticketselectie]', webform_submission) }}. In this example "ticketselectie" is the name of the checkbox element with 4 checkboxes in it (options). What you get from this is a string containing the option text for each checked checkbox, seperated by comma.
    1. You can use the twig split filter to extract an array out of checked checkboxes.
    2. Turns out you need to use data.custom_composite_element.0.element_key as the syntax. given that a custom composite element only ever has one row, it's always the 0 delta you need, and then the name of the key behind that. So given a custom composite with the name "abonnementen", and in there two number fields with the names "minderjarigen" and "anderen", that leaves with the following syntax: data.abonnementen.0.anderen or data.abonnementen.0.minderjarigen

That's it really. Took way too long to find that, and it's kind of weird to me that the "data." syntax didn't work for the checkbox element. So if anyone knows a better way, please do reply.

0

I suppose the elements documentations is a bit misleading. You can always try debugging like this:

{{ context|keys|join('+') }}
{{ data|keys|join('+') }}
{{ data|join('+') }}

which brought me to conditions like

{% if data.mycheckboxes %}

{% if mykey in data.mycheckboxes %}

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.