webonaute/twig-debug-helper-bundle
A Symfony bundle that adds Twig debugging helpers, giving you handy functions and filters to inspect variables, dump values, and trace template output during development.
This is a Symfony bundle, not a Laravel package — the assessment below assumes you're either working in a Symfony app or evaluating whether the idea is worth porting to Blade.
Install as a dev-only dependency so it never ships to production:
composer require --dev webonaute/twig-debug-helper-bundle
Register it in config/bundles.php (Flex may do this automatically — if not, add it manually and scope it to dev):
return [
// ...
Webonaute\TwigDebugHelperBundle\TwigDebugHelperBundle::class => ['dev' => true],
];
Then check the bundle's README for the exact config key — the repo is from 2018 and the docs are thin. Look first at:
TwigDebugHelperBundle) to see what it registers (a Twig extension, a loader decorator, or a compiler pass).Resources/config/ services file — that tells you what's actually wired up.enabled: true flag in config/packages/dev/.First use case: render any page, hit View Source, and look for HTML comment markers around rendered fragments (typically <!-- START templates/foo.html.twig --> ... <!-- END -->). That tells you which template emitted the markup you're hunting — exactly the problem it solves when a stray <div> appears in a page built from ten nested {% include %}s.
After enabling, always run:
bin/console cache:clear
The bundle decorates Twig, so a stale compiled-template cache will make it look broken.
1. Source-view debugging loop. The day-to-day workflow is: bug report → view source → locate the comment boundary around the offending markup → open that template. Use it instead of {{ dump() }} when you don't know which template to dump from.
2. Wrap only what you're chasing. If the bundle supports a per-block tag or function (check the extension), annotate suspicious partials rather than the whole request — output stays readable and diffs stay small.
3. Pair it with the Symfony Profiler. Twig's own profiler tells you render times; this bundle tells you render locations. Open the profiler's Twig panel first to find the slow/duplicated template, then view source to see where its output landed.
4. Use it during refactors. When extracting a monolithic template into partials, the comment markers give you an instant before/after map proving each chunk came from the file you expect.
5. Porting the idea to Laravel. There's no drop-in equivalent. Two lightweight options:
@traceStart('partials.card') / @traceEnd, implemented in a service provider with Blade::directive(...).View::composer(...), appending a comment when app()->isLocal().Either keeps the "where did this HTML come from?" capability without inheriting a dead Symfony bundle.
<script>/<style> blocks, emails, and anything diffed or signed. Scope it to the routes that render real HTML, or disable it per-request.cache:clear and confirm the compiled templates under var/cache/dev/twig/ were regenerated. Half of all "it doesn't work" reports for Twig decorator bundles are cache issues.LoaderInterface, it can affect template resolution order or namespaced paths (@Acme/...). Diagnose with bin/console debug:twig and bin/console debug:container | grep -i twig before and after enabling.Twig\Extension\AbstractExtension service tagged twig.extension. You get the marker behaviour back without depending on a 7-year-old bundle's compiler pass.composer require this into a Laravel app and get anything useful — it depends on symfony/framework-bundle. Treat it as a design reference; the Blade directive in Implementation Patterns is roughly an afternoon of work and won't rot.How can I help you explore Laravel packages today?