Skip to main content

Devbit

Twig debugging via IDE Breakpoint in PHPStorm with Drupal

While developing a frontend theme you want to debug in a similar fashion as you would do with PHP code in your IDE, including the option to stop code interpretation at certain lines.
Screenshot of PHPStorm config.

Issue:

While developing a frontend theme you want to debug in a similar fashion as you would do with PHP code in your IDE, including the option to stop code interpretation at certain lines.

Solution:

To enable twig debugging without writing {{ drupal_breakpoint() }} or {{ twig_debug }} into the templates, you can define the Twig cache directory in PHPStorm to tell it, where the compiled templates get written to.

This way, you can then use the "normal" PHP-Debugging feature in Twig-Files by simply adding a breakpoint (red dot) to the twig line where something is executed.

Profilfoto Peter Gerken

Peter Gerken

Solution Architect / UX Konzeption / Frontend Developer

Ihre Drupal-Website zukunftssicher machen

Wir prüfen Ihr System und zeigen, was Sie für AI, Wartung und Upgrades brauchen.