Twig Xdebug

Component ID

2697135

Component name

Twig Xdebug

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

33868

Component created

Component changed

Component body

Note: If you have Devel installed already, it provides a similar functionality.

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.