zenstruck/twig-service-bundle
Twig Service Bundle adds a service() function to Twig so templates can fetch Symfony services directly by ID, e.g. {{ service('my_service') }}, plus service_exists() for safe checks. It keeps controllers thin and avoids writing custom Twig extensions just to expose a service.
twig/twig plus a Twig-for-Laravel bridge — an extra moving part and a second templating dialect alongside Blade. For a Laravel shop, this is a "no" on fit before any feature merits are discussed; for a Symfony shop, it's a genuine "maybe."Adopt when:
Look elsewhere when:
@inject, view composers, and custom directives already solve most of this natively; introducing Twig to get this package is a poor trade.To executives: This is a small, MIT-licensed utility that removes a recurring bottleneck — the "we just need one value on one page" request that currently consumes an engineering cycle. It is cheap to trial and cheap to abandon. The honest caveat: it is a niche, low-adoption package (double-digit stars, no downstream dependents), so recommend it as an optional developer tool with a bounded pilot, not as core platform infrastructure. Success looks like fewer template-helper tickets and no increase in template-related defects.
To engineering: One Composer dependency that exposes functions, static methods, and Symfony service methods to Twig, replacing a class-per-helper pattern. It's maintained (recent release) and permissively licensed. Two conditions for approval: (1) confirm we're standardized on Twig — if the ask is really about Laravel, this is the wrong tool and we should use Blade primitives; (2) we publish an allow-list of read-only services and keep mutating services out of templates. If either condition fails, we build the thin extension layer instead.
How can I help you explore Laravel packages today?