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 Lambda

Twig Lambda Laravel Package

dpolac/twig-lambda

Adds lambda and arrow-function syntax to Twig templates, letting you write inline closures like map((x) => x * 2) directly in your templates. A small, focused extension for cleaner data transformations without custom filters or PHP callbacks.

Deep Wiki
Context7

dpolac/twig-lambda brings arrow functions to Twig, letting you write lambdas directly in templates instead of registering named callables or working around loop variables. Inline expressions such as {{ numbers|map(n => n * 2) }} or {{ users|filter(u => u.active) }} keep templates concise and readable.

  • Inline lambda syntax — x => x * 2, plus multi-parameter forms like (a, b) => a + b
  • Works with existing filters — map, filter, reduce, sort, and any callable-accepting function
  • No PHP boilerplate — no named callables, closures, or extension code needed
  • Composable expressions — chain lambdas through pipelines for expressive data transforms

Ideal for quick collection transformations where a full PHP helper would be overkill.

Frequently asked questions about Twig Lambda
How do I install dpolac/twig-lambda in a Laravel app?
Install it with Composer using composer require dpolac/twig-lambda, then register the extension in your Twig environment. In a Laravel app that means the Twig environment configured by TwigBridge or your custom Twig service, not a Blade service provider. Treat installation as a spike until you confirm the package's Twig API assumptions match your installed Twig version.
Does dpolac/twig-lambda work with Laravel Blade?
No. dpolac/twig-lambda is a Twig extension, so it provides no direct value in a standard Laravel Blade codebase. It only makes sense if your application deliberately renders views with Twig, typically through rcrowe/twigbridge or a custom Twig environment.
Which Twig versions does dpolac/twig-lambda support?
The package has no current release after 2018-06-06, so its supported Twig range is tied to that era and must be verified against your installed Twig version. Modern Twig 2, 3, or 4 projects should assume incompatibility until a spike proves otherwise. Pin Twig and the extension explicitly and run composer why-not checks before adopting it.
Is dpolac/twig-lambda compatible with PHP 8?
Likely not without validation or patching. The last release predates current PHP 8.x releases, so PHP 8 deprecations or fatal errors are a realistic risk. Test the package under your exact PHP and Twig matrix, and expect to fork or patch it if you need modern runtime support.
How do I register the Twig Lambda extension in Laravel TwigBridge?
Registration depends on how your Laravel app builds its Twig environment. With TwigBridge, confirm the supported extension registration mechanism for your TwigBridge version, then add the Twig Lambda extension to that environment. Validate template cache invalidation and error handling after registration, because an incorrectly registered extension can fail only at render time.
Is dpolac/twig-lambda still maintained?
Effectively unmaintained. The last release was 2018-06-06, the repository is unknown in this assessment, and the package has about 45 stars. Adoption means your team owns compatibility patches, dependency pinning, and an eventual replacement plan.
What alternatives exist for map, filter, and reduce in Twig?
Native Twig may already cover some collection work, and maintained Twig extensions can provide map, filter, or lambda-style helpers. Before adding an old dependency, check whether your Twig version or existing extensions already support the behavior you need. If not, a small internal Twig extension is often safer than an unmaintained package for a narrow feature.
Can I use dpolac/twig-lambda in production?
It is high risk as a production dependency: abandoned upstream maintenance, no security patch path, Twig API drift, and PHP 8 compatibility concerns. If you must use it, isolate it behind an internal adapter, pin versions, add regression tests, and canary it in non-critical templates. Do not make it a strategic platform dependency.
How do I test Twig lambda expressions in Laravel?
Test lambdas through rendered Twig templates rather than only unit-testing the extension. Cover map, filter, reduce, edge-case collections, error handling, and template cache behavior in a disposable branch or spike. Wrap the extension in application-owned code so you can swap it out without rewriting templates.
Can I fork or vendor dpolac/twig-lambda if it is abandoned?
Yes, forking or vendoring is the realistic path if you adopt it. Because the upstream repository is unknown and the last release is from 2018, plan to own patches for PHP and Twig upgrades. Pin the package, document the fork, and keep an internal adapter so you can replace it later.
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.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
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