PHPackages                             cviebrock/twig-group - 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. cviebrock/twig-group

ActiveLibrary[Templating &amp; Views](/categories/templating)

cviebrock/twig-group
====================

Twig filter that splits an array into a given number of groups (unlike batch, which splits the array based on items per group)

1.0.0(11y ago)23.6kMITPHPPHP &gt;=5.3.0

Since Mar 17Pushed 11y ago2 watchersCompare

[ Source](https://github.com/cviebrock/twig-group)[ Packagist](https://packagist.org/packages/cviebrock/twig-group)[ Docs](http://github.com/cviebrock/twig-group)[ RSS](/packages/cviebrock-twig-group/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

twig-group
==========

[](#twig-group)

Twig filter that splits an array into a given number of groups. This is different than the built-in `batch` filter, which splits the array based on a given number of items *per* group..

[![Total Downloads](https://camo.githubusercontent.com/939f86c244bb3bdc260d97a9dd7e9ff953aa43160bde813ec656827e40ee6b25/68747470733a2f2f706f7365722e707567782e6f72672f6376696562726f636b2f747769672d67726f75702f646f776e6c6f6164732e706e67)](https://packagist.org/packages/cviebrock/twig-group)[![Latest Stable Version](https://camo.githubusercontent.com/d97f63830f8e4cfc311fa47a5269c542bdee765cf8a3653baea12c590956d2be/68747470733a2f2f706f7365722e707567782e6f72672f6376696562726f636b2f747769672d67726f75702f762f737461626c652e706e67)](https://packagist.org/packages/cviebrock/twig-group)

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

[](#installation)

The filter is registered at Packagist as [cviebrock/twig-group](https://packagist.org/packages/cviebrock/twig-group) and can be installed using [composer](http://getcomposer.org/):

```
composer require cviebrock/twig-group
```

Or just download the zip file and copy the file into your *src* folder.

Enable the extension:

```
$twig = new Twig_Environment($loader, $options);
$twig->addExtension(new Cviebrock\Twig\GroupExtension());
```

If you are using Laravel and [rcrowe/twigbridge](https://github.com/rcrowe/TwigBridge), then enable the extension by adding an entry to the `enabled` array in `app/config/packages/rcrowe/twigbridge/extensions.php`:

```
'enabled' => [
	...
	'Cviebrock\Twig\GroupExtension',
],
```

Usage
-----

[](#usage)

Assume we are starting with the following array:

```
[ 'John', 'Jane', 'Bill', 'Bob', 'Mary' ]

```

Pass the array and number of groups to the filter:

```
{{ array | group(2) }}          // [ ['John', 'Jane', 'Bill'], ['Bob', 'Mary'] ]

{{ array | group(3) }}          // [ ['John', 'Jane'], ['Bill', 'Bob'], ['Mary'] ]
```

Optionally pass a second parameter which will pad out all the arrays so they have the same number of elements (similar to how the built-in `batch` filter pads arrays:

```
{{ array | group(2, '-empty-') }}          // [ ['John', 'Jane', 'Bill'], ['Bob', 'Mary', '-empty-'] ]

{{ array | group(3, '-empty-') }}          // [ ['John', 'Jane'], ['Bill', 'Bob'], ['Mary', '-empty-'] ]
```

Bugs, Suggestions and Contributions
-----------------------------------

[](#bugs-suggestions-and-contributions)

Please use Github for bugs, comments, suggestions.

1. Fork the project.
2. Create your bugfix/feature branch and write your (well-commented) code.
3. Commit your changes and push to your repository.
4. Create a new pull request against this project's `master` branch.

Copyright and License
---------------------

[](#copyright-and-license)

**twig-group** was written by Colin Viebrock and released under the MIT License. See the LICENSE file for details.

Copyright 2015 Colin Viebrock

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

4073d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a3b6c8249f9ade65deeb3667fdf717ca934828c0c5fd2341dfdb62ab01414791?d=identicon)[cviebrock](/maintainers/cviebrock)

---

Tags

twigtemplatingfilterbatchgroup

### Embed Badge

![Health badge](/badges/cviebrock-twig-group/health.svg)

```
[![Health](https://phpackages.com/badges/cviebrock-twig-group/health.svg)](https://phpackages.com/packages/cviebrock-twig-group)
```

###  Alternatives

[timber/timber

Create WordPress themes with beautiful OOP code and the Twig Template Engine

5.7k3.4M111](/packages/timber-timber)[dpolac/twig-lambda

Lambda expressions for Twig and filters that make use of them

45205.4k1](/packages/dpolac-twig-lambda)[shoot/shoot

Shoot aims to make providing data to your templates more manageable

40229.9k2](/packages/shoot-shoot)[goetas/twital

PHP templating engine that combines Twig and PHPTal power points

13013.1k1](/packages/goetas-twital)[goetas/twital-bundle

Twital templating engine Symfony Bundle

206.8k](/packages/goetas-twital-bundle)[tommcdo/kohana-twig

Kohana 3.3 module for the popular Twig template engine

241.9k](/packages/tommcdo-kohana-twig)

PHPackages © 2026

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