Twig\Error\SyntaxError: Unknown "drupal_field" function.

Created on 30 May 2024, 11 months ago

After installing twig_tweak and clearing the Drupal cache, when I try to use the drupal_field() function in a template, I get the error...

Twig\Error\SyntaxError: Unknown "drupal_field" function.

The template where I am trying to use drupal_field() is views-view-fields.html.twig.

My Drupal version is 10.2.2.

๐Ÿ› Bug report
Status

Active

Version

3.3

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States arnoldbird

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

Comments & Activities

  • Issue created by @arnoldbird
  • ๐Ÿ‡ท๐Ÿ‡บRussia Chi

    Do other TT functions work for you?

  • Status changed to Closed: works as designed 11 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States arnoldbird

    I can no longer reproduce the bug. I suspect the bug was occurring because I was misusing a views template. The drupal_field() function is working fine in other contexts.

  • Status changed to Active about 1 month ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia vinaygawade Sawantwadi, Maharashtra

    I updated my site from Drupal 10.3.* to Drupal 10.4.3 and ran updates, but I'm still encountering the following error:

    Twig\Error\SyntaxError: Unknown "isTranslationMessageShouldDisplay" function. in Twig\ExpressionParser->getFunction()
    

    Hereโ€™s how I defined the function:

    /**
       * {@inheritdoc}
       * Returns custom Twig functions to Drupal.
       */
      public function getFunctions() {
        return [
          new \Twig\TwigFunction('get_display_name', [$this, 'get_display_name']),
          new \Twig\TwigFunction('isTranslationMessageShouldDisplay', [$this, 'isTranslationMessageShouldDisplay']),
        ];
      }
    

    I have cleared the cache multiple times, but the issue persists. I'm not sure what is causing this error. Any insights would be appreciated!

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia vinaygawade Sawantwadi, Maharashtra

    After updating the core and other modules locally and running the update script, the Admin Toolbar Links Access Filter module was being uninstalled. Since the my custom module depended on it, it was also uninstalled, leading to the previously mentioned issue.
    I fixed it now.

  • I'm facing the similar issue, pls provide a solution to resolve this. I have issues with multiple functions defined in the TwigExtenion

Production build 0.71.5 2024