Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Twig Injection Bundle

Twig Injection Bundle Laravel Package

intaro/twig-injection-bundle

Symfony bundle that injects container services into Twig templates, letting views call service methods directly instead of adding controller boilerplate. Configure exposed services and reuse them as handy view helpers for routing, formatting, and other presentation logic.

View on GitHub
Deep Wiki
Context7

The TwigInjectionBundle allows to inject twig templates through the event behavior

Frequently asked questions about Twig Injection Bundle
Is intaro/twig-injection-bundle a Laravel package?
No. intaro/twig-injection-bundle is a Symfony bundle that relies on Symfony's bundle registration, DI container extension, and Twig/HTTP kernel event system. Laravel has no concept of a bundle and no Kernel::registerBundles(), so it will not work as a drop-in Laravel package. In a Laravel app the native equivalents are Blade view composers, the @inject directive, and @stack/@push directives.
Can I install intaro/twig-injection-bundle in Laravel with Composer?
Composer may resolve the package, but installing it does not make it functional in Laravel. The bundle's service subscribers and Twig extensions must be registered by a Symfony kernel, so you would need a Twig bridge such as rcrowe/twigbridge plus a custom service provider that manually re-registers the bundle's listeners. That is effectively a port, not an install-and-configure step.
What is the Laravel equivalent of injecting services into Twig templates?
Laravel ships this capability natively through Blade. Use the @inject directive to resolve a service into a view, or register a view composer to bind data to a template. The @stack and @push directives cover the other common use case of letting extension code add markup to templates it does not own.
How do I use the @inject directive in Laravel Blade?
Write @inject('metrics', 'App\Services\MetricsService') at the top of the Blade file, then call $metrics->method() anywhere in that template. Laravel resolves the class from the service container at render time. For repeated or shared logic, a view composer registered in a service provider is usually cleaner.
Does intaro/twig-injection-bundle work with Laravel 10 or Laravel 11?
Not out of the box. Laravel 10 and 11 ship Symfony 6.x components, but they do not provide the bundle kernel, bundle registration, or event dispatcher wiring the package expects. You would have to port the portable Twig and listener logic into a Laravel service provider before it could run.
Which PHP and Symfony versions does twig-injection-bundle 3.0.0 require?
Version 3.0.0 drops support for PHP 7 and Symfony 3, so it targets PHP 8+ and modern Symfony releases. Check the composer.json in the tagged release for the exact constraint ranges. The bump is a hard breaking change with no deprecation path, so older stacks must stay on v2.2.1, which is no longer supported.
How do I expose a service to a Twig template with this bundle?
You declare the services you want available in the bundle configuration, then call their methods from Twig templates as view helpers. This lets views use routing, formatting, and other presentation logic without controller boilerplate. Confirm the exact configuration keys and service tags against the bundle's README before relying on them.
How do I port twig-injection-bundle to Laravel?
Separate the portable pieces, mainly Twig\Environment manipulation and the injection listener logic, from the Symfony-only scaffolding such as the Bundle subclass and DI extension. Re-express the result as a Laravel service provider using view composers or a custom Blade directive. Expect roughly one to two days for a native reimplementation versus three to five days to fork and maintain a port.
Is intaro/twig-injection-bundle maintained and safe for production?
Adoption signals are weak: around seven stars, zero dependents, and a single-vendor origin, so it has little outside validation or bug-report surface. Version 3.0.0 shows the maintainer is still cutting majors and modernizing constraints, which is a positive maintenance signal. The MIT license makes forking legally clean, but for a Laravel codebase you are better served by Blade's built-in features.
Should I use Twig or Blade in a Laravel application?
Use Blade unless you have a concrete reason to keep Twig, such as an existing Twig template library you must reuse. Blade is native, requires no extra packages, and already provides @inject, view composers, and stacks for everything this bundle offers. Adding Twig through a bridge increases the third-party surface and maintenance burden for little gain.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core