Print webform element in twig template file

Created on 13 May 2020, over 4 years ago
Updated 18 October 2023, about 1 year ago

I'm using this module with Dompdf engine for theming a webform submission.

So, in my custom theme I have create this file: entity-print--webform-submission--testform.html.twig

How do I print the elements of the webform? I think I understand I have to use the content variable, but I can't understand how.

Example, if in my webform there are element1 and element2, how do I print its in my custom twig template file?

And, how do I print the header and the footer too?

💬 Support request
Status

Active

Version

2.1

Component

Code

Created by

🇮🇹Italy kris77

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇩Indonesia tinohuda

    Hi @Kris77

    Thank for your code above.

    I can use {{ content }} and all content can be print out in pdf.

    But how to print out particular webform elements label and its values?

    I try to use {{ data.field1 }} but nothing printed.

    Please help anyone and thank before.

  • 🇨🇦Canada orizonmedia

    @tinohuda did you make this working in D9? I added the preprocess to my .theme but still unable to print element with   {{ data.field1 }} {{ elements.processed_text_01 }} ...

  • 🇨🇿Czech Republic milos.kroulik

    First of all, this probably doesn't belong here.

    Anyway, the solution in https://www.drupal.org/project/entity_print/issues/3136298#comment-13843190 💬 Print webform element in twig template file Active doesn't work now, because $variables['content'] contains only already rendered HTML. But in the same preprocess, there's actually a $webform_submission variable available.

  • 🇮🇩Indonesia tinohuda

    @orizonmedia I use {{ webform_submission.data.field1 }} and its worked. To make sure i use the Devel.

Production build 0.71.5 2024