oro/twig-inspector
Oro Twig Inspector helps developers quickly identify which Twig templates and blocks render parts of an HTML page, making it easier to debug and customize layouts during development. Includes documentation and installation guides; MIT licensed.
Installation:
composer require oro/twig-inspector
Add the bundle to config/bundles.php (Symfony) or register the service provider in config/app.php (Laravel via Symfony bridge).
Enable in Dev Environment:
Ensure the bundle is only active in APP_ENV=dev by checking the KERNEL environment variable or Symfony’s APP_DEBUG mode.
First Use Case:
Visit /_inspector (default route) to see a live list of all Twig templates and blocks rendered on the current page. Useful for debugging layouts, partials, or inherited blocks.
Debugging Template Hierarchy:
body_content is overridden in a child template.Performance Profiling:
Collaboration:
base.html.twig to layout.html.twig").Integration with Laravel:
symfony/twig-bridge), ensure the inspector’s routes are excluded from production by middleware:
Route::middleware(['web', 'inspector'])->group(function () {
// Inspector routes
});
Customizing Output:
twig.inspector.data_provider service) to add custom metadata (e.g., template file size, last modified time).Route Conflicts:
/_inspector route may clash with existing routes. Rename it in config/packages/oro_twig_inspector.yaml:
oro_twig_inspector:
route: /debug/twig
Caching Issues:
php artisan cache:clear or php bin/console cache:clear).config/packages/twig.yaml if inspector data appears stale:
twig:
auto_reload: true
Laravel-Specific Quirks:
Performance Overhead:
APP_ENV=testing php artisan serve
Filtering Templates:
header).?_inspector=blocks to focus on specific data.Template Line Numbers:
Extending Data:
Oro\TwigInspectorBundle\DataProvider\TemplateDataProvider service:
services:
App\TwigInspector\CustomDataProvider:
decorates: oro_twig_inspector.data_provider.template
arguments: ['@.inner']
Headless Mode:
oro_twig_inspector:
enabled: false
Then use the underlying data provider programmatically:
$provider = $container->get('oro_twig_inspector.data_provider.template');
$templates = $provider->getTemplates();
How can I help you explore Laravel packages today?