Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Twig_Error_Syntax' with message 'Unknown "render" filter

Tags:

I'm running drupal 8, composer and npm to perform gulp tasks.

When I run npm start.. my task manager: I get the following stack trace:

Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'Unknown "render" filter.' in /web/project/web/themes/emulsify/components/_patterns/04-templates/basic-page/_basic_page.twig:26 Stack trace: #0 /web/project/web/themes/emulsify/pattern-lab/vendor/twig/twig/lib/Twig/ExpressionParser.php(481): Twig_ExpressionParser->getFilterNodeClass('render', 26) #1 /web/project/web/themes/project_theme/pattern-lab/vendor/twig/twig/lib/Twig/ExpressionParser.php(466): Twig_ExpressionParser->parseFilterExpressionRaw(Object(Twig_Node_Expression_Name)) #2 /web/project/web/themes/project_theme/pattern-lab/vendor/twig/twig/lib/Twig/ExpressionParser.php(320): Twig_ExpressionParser->parseFilterExpression(Object(Twig_Node_Expression_Name)) #3 /web/project/web/themes/project_theme/pattern-lab/vendor/twig/twig/lib/Twig/ExpressionParser.php(212): Twig_ExpressionParser->parsePostfixExpression(Object(Twig_Node_Expression_Name)) #4 /web/project in /web/project/web/themes/project_theme/components/_patterns/04-templates/basic-page/_basic_page.twig on line 26 

I've looked at installing twig-bridge / symfony twig via composer but I can't seem to get rid of the error message.

Do I just ditch using the twig filter "render"?


Update: 14/08/17

I've also ran into the same problem when trying to use the drupal_block function provided via Drupal 8's twig_tweak module.

like image 283
cwiggo Avatar asked Jul 17 '17 11:07

cwiggo


1 Answers

The problem in the code above is that your Twig extension class is extending the internal Drupal Twig extension class. That breaks the Twig extensions added by Drupal core and that's why you are getting the error.

To fix this, you should make your Twig extensions extend Twigs internal Twig extension class. Your class should be defined like this:

class MyExtension extends \Twig_Extension { 

After making that change, you can also remove arguments set for that class from the MODULE.services.yml

link

like image 60
Maxim Strutinskiy Avatar answered Sep 21 '22 12:09

Maxim Strutinskiy