hec-franco/twig-inspector
Twig Inspector adds debugging tools for Twig templates, letting you trace which template rendered each part of a page and inspect variables, includes, and blocks directly from the browser. A practical helper for faster template debugging and clearer view-layer insight.
Before doing anything, confirm the premise: this package inspects Twig templates, and Laravel ships Blade. There is no value here unless your app renders Twig — typically via rcrowe/twigbridge or a legacy Symfony front-end served alongside a Laravel API. If you can't point at a .twig file that gets rendered in your stack, stop and close the tab.
Assuming you do render Twig:
composer.json and the README and look for:
extra.laravel.providers entry (auto-discovery) or a Symfony Bundle class.dev-main, you'll pin by commit SHA).composer require --dev hec-franco/twig-inspector
Then immediately commit an exact constraint — "dev-main#<sha>" if there are no tags. Do not float on ^1.0; there is no release history to protect you.NOASSERTION means Composer could not identify the license from metadata. Open LICENSE and read it. An unclear license is a hard gate, even for require-dev.app/Providers/ (or config/app.php) and have it no-op outside local.First use case, in order:
local with APP_DEBUG=true.layout.twig → section.twig → component.twig).file:line. That's the payoff — "which template emitted this <div>?"If the output doesn't beat {{ dump() }} + Xdebug in the first ten minutes, stop. The package's only job is to be faster than your existing debugging loop.
Gate on environment in code, not documentation. Register the insprector's extension against the Twig Environment only when app()->environment('local') and a dedicated flag (e.g. TWIG_INSPECTOR=true) are both true. A single mis-set env var across shared dev/staging is how this tool ends up leaking template paths into a staging response.
Wire it through TwigBridge, not the package. The inspector needs to decorate the same Environment instance TwigBridge renders through. Get the environment from the container (typically the twig binding) and register the extension/node-visitor there. Write the adapter yourself and own it — don't assume the package provides Laravel glue.
// app/Providers/TwigInspectorServiceProvider.php (skeleton)
public function register(): void
{
if (! $this->app->environment('local') || ! env('TWIG_INSPECTOR', false)) {
return;
}
// Defer: resolve twig environment after TwigBridge has booted.
}
Workflow pattern — enable, inspect, disable. Treat this like Debugbar: on when you're actively chasing a "where did this come from?" bug, off otherwise. Keep it out of your default local bootstrap if your test suite renders Twig, because injected markup will break snapshot assertions (see Gotchas).
Pair it with targeted logging. The inspector tells you which template; it does not tell you what variables were in scope. Combine it with a small middleware or a Twig dump extension to print the context array for the template you just identified. That two-step (locate template → inspect its context) is the actual diagnostic loop this tool accelerates.
Don't use it for production observability. Scope it strictly to local development. If you need to understand template rendering in staging/production, reach for structured logging, Sentry breadcrumbs, or an OpenTelemetry span around the render — not markup injection.
CI guard. Add a check that fails if hec-franco/twig-inspector appears in the non-dev autoload/require graph. It's a two-line composer show --no-dev grep and it prevents the most expensive misuse of this package.
curl the page.Accept header or route, not just environment.APP_ENV=testing, not local) or update snapshots — but don't let it silently leak into CI comparisons.data-* attributes or comments can trip a strict CSP, break naive HTML parsers in JS, and inflate response bytes. Measure the delta on one representative page before you roll it out across a team.NOASSERTION blocks adoption regardless of everything else. Get a human to read LICENSE and sign off before code enters the monorepo — even as require-dev.How can I help you explore Laravel packages today?