2017 © Pedro PelĂĄez
 

library twig-sort-by-field

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

image

snilius/twig-sort-by-field

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

  • Wednesday, January 27, 2016
  • by victorhaggqvist
  • Repository
  • 3 Watchers
  • 49 Stars
  • 121,011 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 21 Forks
  • 8 Open issues
  • 8 Versions
  • 10 % Grown

The README.md

Twig SortByField Extension

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

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

Install

With composer, (*3)

composer require snilius/twig-sort-by-field

Usage

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

$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., (*5)

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

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.

The Versions

27/01 2016

dev-master

9999999-dev

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

  Sources   Download

Apache-2.0

The Development Requires

by Victor HĂ€ggqvist

27/01 2016

v0.1.5

0.1.5.0

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

  Sources   Download

Apache-2.0

The Development Requires

by Victor HĂ€ggqvist

27/01 2016

dev-collections

dev-collections

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

  Sources   Download

Apache-2.0

The Development Requires

by Victor HĂ€ggqvist

17/11 2015

v0.1.4

0.1.4.0

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

  Sources   Download

Apache-2.0

The Development Requires

by Victor HĂ€ggqvist

09/07 2015

v0.1.3

0.1.3.0

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

  Sources   Download

Apache-2.0

The Development Requires

by Victor HĂ€ggqvist

05/03 2015

v0.1.2

0.1.2.0

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

  Sources   Download

Apache-2.0

The Development Requires

by Victor HĂ€ggqvist

05/03 2015

v0.1.1

0.1.1.0

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

  Sources   Download

Apache-2.0

The Development Requires

by Victor HĂ€ggqvist

05/03 2015

v0.1.0

0.1.0.0

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

  Sources   Download

Apache-2.0

The Development Requires

by Victor HĂ€ggqvist