1

I am trying to debug Twig templates in Drupal 9, using WAMP, Apache Netbeans, and the Twig Xdebug module on Windows 7.

I have already set up NetBeans so I can debug PHP code in Drupal 9. They are working.
I run my Drupal 9 local test site in WAMP, using the following lines in the php.ini configuration file.

; XDEBUG Extension
[xdebug]
zend_extension="e:/wamp64/bin/php/php7.4.0/zend_ext/php_xdebug-2.8.0-7.4-vc15-x86_64.dll"
xdebug.remote_enable = On
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = Off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir ="e:/wamp64/tmp"
xdebug.show_local_vars=0
xdebug.idekey = netbeans-xdebug
output_buffer = off
xdebug.remote_port = 9000

I have also enabled the Twig debugging in the services.yml file. I have added a {{ breakpoint() }} line in the page.html.twig file located in templates directory for the theme I am using. I also use Google Chrome with the Xdebug helper extension, which I set to Debugging enabled for the address of the local Drupal site (turned green) and its IDE key option to netbeans-xdebug.
Debugging PHP code works perfectly, as I mentioned previously, but I don't get any code break in the break-point line of the template file when I refresh the front page (I have also cleared the cache). In other words, I cannot debug Twig templates.

Is something missing or wrong in my procedure?

I am supposed to turn on the connection-listening in my IDE, but NetBeans has no such button. Since it works with PHP debugging, I guess it listens to connections.

I have followed the methodology described in the Twig Xdebug project page and on Debug Drupal 8 Twig Templates with the Twig_Xdebug Module.

1
  • 2
    You need to add the twig debug module.
    – Kevin
    Commented Jul 16, 2022 at 10:38

1 Answer 1

2

Enabling that flag in the YAML file is not enough to talk to xDebug, you also need the Twig XDebug module to bridge the gap:

https://www.drupal.org/project/twig_xdebug

Once that is installed, you can step through Twig templates with xdebug.

Noted from the docs: https://www.drupal.org/docs/theming-drupal/twig-in-drupal/debugging-twig-templates#s-viewing-variables

4
  • Sorry, but I referred that I also use Twig Xdebug Drupal module in the beginning of my post. Quoting my post start: "I have been trying to debug Twig templates in Drupal 9, using WAMP, Apache Netbeans and Twig Xdebug Drupal module in a Windows 7 OS."
    – vasilis
    Commented Jul 18, 2022 at 5:50
  • If you installed the module with Composer and enabled it, have you cleared the cache and restarted wamp? Not sure what else to say since this module has worked and no visible issues exist. I'd try another editor to rule out netbeans.
    – Kevin
    Commented Jul 18, 2022 at 11:22
  • Yes, I have cleared the cache and restarted wamp. Have you tried Netbeans for Twig debugging in this procedure? Maybe it is Netbeans that doesn't fit here.
    – vasilis
    Commented Jul 19, 2022 at 5:29
  • I only use PHPStorm
    – Kevin
    Commented Jul 19, 2022 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.