PHPackages                             nystudio107/craft-closure - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. nystudio107/craft-closure

Abandoned → [twigphp/Twig](/?search=twigphp%2FTwig)ArchivedYii2-extension[Templating &amp; Views](/categories/templating)

nystudio107/craft-closure
=========================

Allows you to use arrow function closures in Twig

1.0.7(1y ago)2250.7k↓30%31MITPHPPHP ^8.0

Since Aug 8Pushed 1y ago3 watchersCompare

[ Source](https://github.com/nystudio107/craft-closure)[ Packagist](https://packagist.org/packages/nystudio107/craft-closure)[ GitHub Sponsors](https://github.com/khalwat)[ RSS](/packages/nystudio107-craft-closure/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (9)Dependencies (5)Versions (10)Used By (1)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/8dc7760a80a435b81ba227078ed3bf3dfa1bca8c9a6eef6a2e1cf76df0345700/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e7973747564696f3130372f63726166742d636c6f737572652f6261646765732f7175616c6974792d73636f72652e706e673f623d7631)](https://scrutinizer-ci.com/g/nystudio107/craft-closure/?branch=develop) [![Code Coverage](https://camo.githubusercontent.com/2500fb92098e64136c34120b1960a24d33efd3da383793ea6bb1ae865682a7ba/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e7973747564696f3130372f63726166742d636c6f737572652f6261646765732f636f7665726167652e706e673f623d7631)](https://scrutinizer-ci.com/g/nystudio107/craft-closure/?branch=develop) [![Build Status](https://camo.githubusercontent.com/11b7bae1e6f29173daffeaa252382f72bcb802db2e28881741f4e7b70e8ab844/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e7973747564696f3130372f63726166742d636c6f737572652f6261646765732f6275696c642e706e673f623d7631)](https://scrutinizer-ci.com/g/nystudio107/craft-closure/build-status/develop) [![Code Intelligence Status](https://camo.githubusercontent.com/e93dacd0dcd7d077d4b66196402cc94029e062a5c5751dd1d05d31737b1e84ff/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e7973747564696f3130372f63726166742d636c6f737572652f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d7631)](https://scrutinizer-ci.com/code-intelligence)

[![No Maintenance Intended](https://camo.githubusercontent.com/d904056147052e22d8e1c7f46bb50293ed2aeb4c43ead9a2d0cf7a48b46d0562/687474703a2f2f756e6d61696e7461696e65642e746563682f62616467652e737667)](http://unmaintained.tech/)

DEPRECATED
==========

[](#deprecated)

This Craft CMS module is no longer supported or maintained, but it is fully functional, and you may continue to use it as you see fit. The license also allows you to fork it and make changes as needed for legacy support reasons.

Instead, use [Twig 3.1.5's native functionality](https://github.com/twigphp/Twig/issues/3192) for arrow functions everywhere.

Closure for Craft CMS
=====================

[](#closure-for-craft-cms)

Allows you to use arrow function closures in Twig

While Closure is a bit of a monkey patch, it's a pretty clean/simple one that relies on functionality that is already built into Twig

Requirements
------------

[](#requirements)

Closure requires Craft CMS 4.x or 5.x

Installation
------------

[](#installation)

To install Closure, follow these steps:

1. Open your terminal and go to your Craft project:

    ```
     cd /path/to/project

    ```
2. Then tell Composer to require the package:

    ```
     composer require nystudio107/craft-closure

    ```

About Closure
-------------

[](#about-closure)

Twig supports arrow function closures, but only in the [filter](https://twig.symfony.com/doc/3.x/filters/filter.html), [map](https://twig.symfony.com/doc/3.x/filters/map.html), and [reduce](https://twig.symfony.com/doc/3.x/filters/reduce.html) filters.

Twig unfortunately [has no plans](https://github.com/twigphp/Twig/issues/3402) to allow for more widespread usage of arrow function closures.

Craft Closure allows you to use arrow function closures anywhere, which is especially useful with [Laravel Collection methods](https://laravel.com/docs/9.x/collections#available-methods), many of which take a closure as a parameter.

Using Closure
-------------

[](#using-closure)

Once you've added the `nystudio107/craft-closure` package to your project, no further setup is needed. This is because it operates as an auto-bootstrapping Yii2 Module.

You can then pass an [arrow function](https://timkelty.github.io/twig-tips/10-arrow-fn.html) closure as a parameter to anything that accepts them, such as many [Laravel Collection methods](https://laravel.com/docs/9.x/collections#available-methods):

```
    {% set collection = collect(['a', 'b', 'c']) %}
    {% set contains = collection.contains((value, key) => value == 'z') %}
```

Or you can assign an arrow function closure to a Twig variable for re-use:

```
    {% set collection = collect(['a', 'b', 'c']) %}
    {% set closure = (value, key) => value == 'a' %}
    {% set contains = collection.contains(closure) %}
```

Using arrow function closures especially useful now that Craft element queries can all return a Collection via the [.collect()](https://docs.craftcms.com/api/v4/craft-db-query.html#method-collect) method.

More on Arrow Functions in Twig
-------------------------------

[](#more-on-arrow-functions-in-twig)

More here: [Twig Arrow Functions](https://craftquest.io/courses/arrow-functions-in-twig)

Closure Roadmap
---------------

[](#closure-roadmap)

Some things to do, and ideas for potential features:

- Initial release

Brought to you by [nystudio107](https://nystudio107.com/)

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~105 days

Recently: every ~56 days

Total

9

Last Release

539d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7570798?v=4)[Andrew Welch](/maintainers/khalwat)[@khalwat](https://github.com/khalwat)

---

Top Contributors

[![khalwat](https://avatars.githubusercontent.com/u/7570798?v=4)](https://github.com/khalwat "khalwat (67 commits)")[![lindseydiloreto](https://avatars.githubusercontent.com/u/5309692?v=4)](https://github.com/lindseydiloreto "lindseydiloreto (1 commits)")

---

Tags

twigcmsclosurefunctionCraftcraftcmsclosuresArrow

### Embed Badge

![Health badge](/badges/nystudio107-craft-closure/health.svg)

```
[![Health](https://phpackages.com/badges/nystudio107-craft-closure/health.svg)](https://phpackages.com/packages/nystudio107-craft-closure)
```

###  Alternatives

[nystudio107/craft-autocomplete

Provides Twig template IDE autocomplete of Craft CMS &amp; plugin variables

44204.4k13](/packages/nystudio107-craft-autocomplete)[wbrowar/guide

A CMS Guide for Craft CMS.

6154.5k1](/packages/wbrowar-guide)[jalendport/craft-preparse

A fieldtype that parses Twig when an element is saved and saves the result as plain text.

1086.4k](/packages/jalendport-craft-preparse)[viget/craft-classnames

Classnames plugin for Craft CMS

1115.5k1](/packages/viget-craft-classnames)[clearbold/fixmealink

Fix Me a Link is a Craft plugin with link utility functions.

151.4k](/packages/clearbold-fixmealink)[verbb/footnotes

Adds a footnotes feature to CKEditor fields and Twig templates.

213.3k](/packages/verbb-footnotes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
