According to the tokens listed in both in the form creation area and in admin/help/token, I have several tokens available including [webform:title], [webform:url], and [webform:id] to name a few.

When I use

{{ drupal_token('webform:title') }}

on my template, all that prints out on the page is [webform:title].

The cool folks over at Drupal Answers helped out by letting me know that "Currently, it looks like the Twig Tweak module's drupal_token Twig function does not support passing in the $data argument, which would contain the webform entity." They suggested I create an issue requesting this feature.

Thanks.

Comments

leraa created an issue. See original summary.

  • Chi committed 050653f on 8.x-1.x
    Issue #2845318 by leraa: drupal_token function does not support passing...
Chi’s picture

Version: 8.x-1.4 » 8.x-1.x-dev
Category: Feature request » Task
Status: Active » Fixed

Good catch. I just added support for the $data argument. You can find it in dev release. Note that to make use of it you should have an appropriate variable in your template which holds required context (Webform in your case).

For instance, node.html.twig template provides a special variable called node. So it's possible to extract tokens from it as follows:
{{ drupal_token('node:title', {node: node}) }}

Thanks for the report.

leraa’s picture

I think I'm not supposed to waste everyone's time and space by saying thank you, but I'm going to do it anyway. Thank you for adding this feature and so quickly!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.