php-debugbar/twig-bridge
Twig bridge for PHP Debug Bar. Installs via Composer and adds DebugBar support to Twig-based apps. Includes a runnable demo using PHP’s built-in server and a PHPUnit test suite with optional Panther browser testing.
php-debugbar/php-debugbar first (e.g., via composer require barryvdh/laravel-debugbar in Laravel apps).composer require php-debugbar/twig-bridge.TwigBridge\Twig\Extension\DebugExtension to your Twig environment.$debugbar['messages']->debug('Test message')—check the Debugbar panel for messages in the browser.$debugbar inside Blade (via @php blocks) or inject \DebugBar\DebugBar into controllers, then call methods like $debugbar->info(), $debugbar->warning(), or $debugbar->addMessage() in Twig via custom extensions (the bridge itself adds the debug() function to Twig).DebugExtension manually:
$twig = new \Twig\Environment($loader);
$twig->addExtension(new \TwigBridge\Twig\Extension\DebugExtension($debugbar));
Then use {{ debug('variable') }} or {{ debug() }} in templates.$debugbar->addCollector(new \DebugBar\DataCollector\VariableCollector(['foo' => 'bar']));
The bridge ensures variables are collected and displayed only when debug mode is enabled, avoiding production overhead.{{ dump(variable) }} (Twig’s built-in) alongside Debugbar’s collector to inspect complex objects via the GUI.laravel-debugbar is installed (it bundles the bridge as a dependency). If using standalone Twig, register DebugExtension manually.{{ debug() }} calls in loops or frequently rendered templates—each invocation serializes data and may slow dev builds. Prefer targeted uses like {{ debug(request().all()) }} only on error pages.$debugbar->addCollector(new \DebugBar\DataCollector\VariableCollector('my_vars', $data));
to avoid overwrites in the "Variables" panel.MessageCollector for user alerts) and map them to Twig via $debugbar['messages']->info('Alert!')—this message then appears in both the "Messages" panel and can be logged alongside template variables.APP_DEBUG=true in Laravel),X-Debugbar-Id header,How can I help you explore Laravel packages today?