umpirsky/twig-php-function
Lightweight Twig extension that lets you call any PHP function directly from your templates with a simple php_function() call. Skip writing custom Twig extensions for quick formatting, hashing, or utility helpers. Works with Twig 2 and 3.
TwigFunction/filter for every PHP helper you want exposed, this is a generic pass-through. It replaces a build task with a dependency add.twigbridge in a Laravel app): this is a tactical unblocker that lets existing PHP helpers keep working in templates while you plan a curated Twig extension set.Consider adopting when:
twigbridge or are running a non-Laravel PHP app. If you're Blade-only, this package is irrelevant.Look elsewhere when:
TwigExtension with named functions/filters is cheaper in cognitive load than a generic escape hatch.For executives: This is a small, MIT-licensed Twig extension that lets templates call PHP functions directly. It's a low-cost, low-risk way to unblock template flexibility and reduce engineering handoffs for small template changes. The trade-off is governance: because it can call almost any PHP function, it should only be used where template authors are trusted. Recommend a time-boxed trial in a non-customer-facing or internal-tooling context, with a planned exit toward a curated, allow-listed Twig extension set as usage matures.
For engineering: A thin, transparent Twig extension — one dependency, no infrastructure, trivial to integrate where Twig is already in play (note: requires Twig via twigbridge or equivalent; not applicable to a Blade-only Laravel app). The core concern is security and maintainability: treating templates as trusted code is a prerequisite, and we should plan to replace the generic pass-through with explicit TwigFunction/filter registrations for any function that becomes load-bearing. Also worth a quick maintenance check given the package's small footprint before we depend on it in production.
How can I help you explore Laravel packages today?