1

I have the following set up on a D8 install using the Flag, Views and Webform modules:

  • A content type named Product with a Flag field that can be set to "Add product to quote" or "Remove product from quote".
  • A view named "My Quote" that displays all products Flagged with "Add product to quote".
  • A Webform named "Get Quote" set up to capture the client's name, email, address, etc.
  • I now need to add the the view for "My Quote" to the Webform in some way.

I see in D7 there was a module called Webform View that provided similar functionality to what I'm looking for. If I understand the Webform Computed Elements correctly there should be a way to do this using Twig or Tokens, but I have no idea how to get the View data using either method.

I would be very grateful if someone could point me in the right direction, or help me understand the Twig syntax for referencing a View so I can use it in my Weform.

3

To embed a View in a Webform, you can use the View element.

Below is the YAML for how you would embed the Frontpage view into a Webform.

frontpage:
  '#type': view
  '#name': frontpage

@see \Drupal\views\Element\View

  • If I may ask another question here; how do I pass the embedded view data to the Webform email/handler? Using [webform_submission:values:element_key] literally displays the text '[webform_submission:values:element_key]' in the email body (where element_key is the name of the element in the form). – flamesquirrel Jun 21 '18 at 12:23
  • Try drupal.org/project/token_embed_views. Beware that allowing a View to be embedded as a token may have some security implications because any View could be exposed to any user via this token. You might also just want to write some custom code that embeds the View in the email – jrockowitz Jun 21 '18 at 12:56
  • Going to give Token Embed Views a try. Thank you again. – flamesquirrel Jun 22 '18 at 8:06

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.