Note: If you use PHPStorm, it provides a similar functionality (blog, docs), as does the Devel module.
This module enables you to use Xdebug breakpoints with Twig templates.
INSTALLATION
On Drupal 8.3.x or higher, use Composer to install the module and its dependencies (with the --dev flag so you can omit it on production builds):
composer require --dev drupal/twig_xdebug
Installation methods for earlier versions are covered in the README.
USAGE
(If you haven't used Xdebug before, you'll want to set it up first.)
Place {{ breakpoint() }}
into your Twig template. The breakpoint won't open in your Twig file. It opens in a file outside your Twig template - BreakpointExtension.php. Here, you still can inspect all of the variables as if you were running Xdebug within the Twig template. The key values you'll see are:
$context
: Variables available to use in the template.
$environment
: Information about the Twig environment, including available functions.
$arguments
: If you supply an argument to breakpoint (e.g. {{ breakpoint(fields) }}
), it'll be viewable here.
GUIDES
Highly recommended:
zakiya's Debug Drupal 8 Twig Templates with the Twig_Xdebug Module
amyvs' Demystifying Rendered Content in Drupal 8 Twig Files
justinlevi's Drupal 8: twig_xdebug module tutorial
HOW IT WORKS
When the Twig compiler hits {{ breakpoint() }}
in your Twig template, it makes a call to a Twig extension where xdebug_break()
is implemented, which triggers Xdebug.
REQUIREMENTS
This module uses the Composer package ajgl/breakpoint-twig-extension.
Project information
- Module categories: Developer Tools
- 2,486 sites report using this module
- Created by charginghawk on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
Releases
Drupal 10 compatibility
Development version: 8.x-1.x-dev updated 25 Mar 2024 at 13:59 UTC