Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal 8 Twig isn't working for Debug

Tags:

php

twig

drupal-8

I have been messing around with Drupal 8 and seen that in the status report it suggested I should add the Twig C Extension, after adding it I begun to get the following error when using Kint in a theme template file.

Warning: file(/Users/jafacakes2011/Sites/site/recipe-hub/vendor/twig/twig/lib/Twig/Environment.php(403) : eval()'d code): failed to open stream: No such file or directory in Drupal\kint\Twig\KintExtension->kint() (line 78 of /Users/jafacakes2011/Sites/site/recipe-hub/modules/contrib/devel/kint/src/Twig/KintExtension.php).

I Installed PHP and Twig using homebrew: brew install php56 php56-twig php56-mcrypt php56-opcache

You can see in the image below that twig is on my php server.

The error lead me to believe that it was a permissions issue, but all permissions seemed ok in the vendor twig folder.

like image 936
jafacakes2011 Avatar asked Mar 18 '16 10:03

jafacakes2011


People also ask

How do I override Twig in Drupal 8?

Overriding templatesLocate the template you want to override. Copy the template file from its core location into your theme folder. Rename the template according to the naming conventions in order to target a more specific subset of areas where the template is used. Modify the template according to your wish.


2 Answers

this seems to be a kint twig extension issues (see this issue in the devel issues queue https://www.drupal.org/node/2731381)

As workaround you can:

  • go to devel settings page and set kint as the default dumper

  • use {{ devel_dump() }} instead of {{ kint() }} for debug variables in twig template

{{ devel_dump() }} not have all the features offered by the kint twig extension but work well and no suffers from this issue.. the output produced by the devel twig extension is almost equal

like image 63
marco Avatar answered Oct 17 '22 07:10

marco


What fixed this for me was going to '/admin/config/development/devel' and changing the Error handlers from "Standard Drupal" to "Kint backtrace above the rendered page." I also set the Variables Dumper to Kint for a nicer output.

like image 38
jimafisk Avatar answered Oct 17 '22 07:10

jimafisk