PHPackages                             nsantos/twig-sort-by-field - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. nsantos/twig-sort-by-field

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

nsantos/twig-sort-by-field
==========================

A Twig Extension filter to sort an array of entries (objects or arrays) by the specified field

v0.1.5(10y ago)018Apache-2.0PHP

Since Mar 5Pushed 7y agoCompare

[ Source](https://github.com/nicolas-santos/Twig-sort-by-field)[ Packagist](https://packagist.org/packages/nsantos/twig-sort-by-field)[ RSS](/packages/nsantos-twig-sort-by-field/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (3)Versions (8)Used By (0)

Twig SortByField Extension [![](https://camo.githubusercontent.com/7aac3bd54243bc766b2afd2d1e8bf8ee47e60c79696435deecfd89d36951d115/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f766963746f726861676771766973742f547769672d736f72742d62792d6669656c642e7376673f7374796c653d666c6174)](https://travis-ci.org/victorhaggqvist/Twig-sort-by-field)
==============================================================================================================================================================================================================================================================================================================================================================

[](#twig-sortbyfield-extension-)

A Twig Extension filter to sort an array of entries (objects or arrays) by an entry field.

Since version 0.1.5 Doctrine collections can be sorted as is with no need to manually extract the array first.

*Fork from victorhaggqvist*

Install
-------

[](#install)

With composer

```
composer require nsantos/twig-sort-by-field

```

Usage
-----

[](#usage)

The list could look like this, but obviously with more than one key per array.

```
$base = array(
  array(
    "name" => "Redmine"
  ),
  array(
    "name" => "GitLab"
  ),
  array(
    "name" => "Jenkins"
  ),
  array(
    "name" => "Piwik"
  )
);
```

```
{% for item in base | sortbyfield('name') %}

    {{ item.name }}

{% endfor %}
```

For Symfony usage you'll want to add it as a service and tag it for Twig.

```
# app/config/services.yml
services:
    twig.extension.sortbyfield:
        class: Snilius\Twig\SortByFieldExtension
        tags:
            - { name: twig.extension }
```

Disable exception on isSortable
-------------------------------

[](#disable-exception-on-issortable)

If for some reason - isSortable fails - do not throw an exception

License
-------

[](#license)

```
Copyright 2015 Victor Häggqvist

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.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 ~65 days

Recently: every ~82 days

Total

6

Last Release

3762d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/70b03ac8c2d16a3beb5db4a7cbbca48b9c8ef5065f2c70467321e20d911fadeb?d=identicon)[nsantos](/maintainers/nsantos)

---

Top Contributors

[![victorhaggqvist](https://avatars.githubusercontent.com/u/1887628?v=4)](https://github.com/victorhaggqvist "victorhaggqvist (21 commits)")[![AMoQu](https://avatars.githubusercontent.com/u/822917?v=4)](https://github.com/AMoQu "AMoQu (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nsantos-twig-sort-by-field/health.svg)

```
[![Health](https://phpackages.com/badges/nsantos-twig-sort-by-field/health.svg)](https://phpackages.com/packages/nsantos-twig-sort-by-field)
```

PHPackages © 2026

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