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.

Comments

arnoldbird created an issue. See original summary.

chi’s picture

Do other TT functions work for you?

arnoldbird’s picture

Status: Active » Closed (works as designed)

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.

vinaygawade’s picture

Version: 3.3.0 » 3.4.0
Status: Closed (works as designed) » Active

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!

vinaygawade’s picture

Status: Active » Closed (works as designed)

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.

ansiya’s picture

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