Closed (fixed)
Project:
Webform
Version:
8.x-5.0-beta24
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
28 Nov 2017 at 14:31 UTC
Updated:
21 Mar 2021 at 15:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
jrockowitz commentedTry using
{{ webform_token('[webform_submission:values:option:entity:title]', webform_submission) }}.We need to better document the
webform_token()Twig function in the UI.Comment #3
jrockowitz commented..and the inline Twig help was broken.
The attached patch fixes the issue.
Comment #4
adrian83 commented@jrockowitz Thank you, the twig token worked for calling a single value. I also applied the patch which fixed the twig help. That is really helpful. When using the twig token, is it possible to do the twig for loop when outputting titles for a multi-value reference field? Or maybe I would be better off working with this: {{ data.element_key.delta }}?
Comment #6
jrockowitz commentedI committed the patch. Please download the latest dev release to review.
Comment #7
adrian83 commentedOK, I updated to dev and the twig help is working. Thank you. I'm still trying to figure out my question in #4.
Comment #8
jrockowitz commentedThe challenge is that the Twig variables don't include formatted values, just the raw data, but you should be able to loop through multiple values.
Comment #9
adrian83 commentedAre you saying that I should be able to loop through multiple values of this:
{{ webform_token('[webform_submission:values:option:entity:title]', webform_submission) }}? Or were you talking about Twig variables?Comment #10
jrockowitz commentedYou have to use the twig variable because webform_token() always returns renderable markup.
Comment #11
adrian83 commentedThanks, I'll post once I have the for loop figured out.
Comment #12
adrian83 commentedProgress report: So far I have these two things working.
I can loop through the entity IDs like this:
I can get a specific entity ID like this:
<p>{{ data.choose_opt.0 }}</p>Still working at making the jump to the entity and its title. This isn't working:
<p>{{ data.choose_opt.0.entity.title }}</p>nor this
<p>{{ data.choose_opt.0.entity.title.value }}</p>I'll post when I have anything new.
Comment #13
adrian83 commentedWith some help from markconroy in the Drupal Twig Slack, here is what I did to print the title of entities referenced earlier in the form. I used twig tweak to load a a media entity view mode which I stripped of all its wrappers. Here is the twig markup:
choose_optelement.Result: On page 1 of the form, user selects several options in an Entity checkboxes element. On page 2 of the wizard, the user sees a summary of what had been selected on page 1. The nice thing is that this method would allow us to load any fields from the referenced entity simply by dragging more fields into the view mode.
Comment #14
jrockowitz commentedWe need to add a link to install the Twig Tweak module.
I am going to reopen this ticket so that I make the change.
Comment #16
jrockowitz commentedComment #17
jrockowitz commentedComment #19
milos.kroulik commentedThe solution in https://www.drupal.org/project/webform/issues/2926806#comment-12363523 is probably too complicated in most cases. Twig Tweak also supports printing field values from referenced entities directly like this:
I'm going to modify this code to send submission to selected people, represented by nodes.
Comment #20
jrockowitz commentedTwig Tweak++