snilius / twig-sort-by-field
此包已被 废弃 且不再维护。没有建议的替代包。
一个Twig扩展过滤器,用于按指定字段对条目数组(对象或数组)进行排序
v0.1.5
2016-01-27 00:29 UTC
Requires (Dev)
- php: >=5.5.9
- doctrine/collections: ^1.3
- phpunit/phpunit: ~4.5
- twig/extensions: ~1.2
This package is not auto-updated.
Last update: 2024-03-31 18:59:16 UTC
README
一个Twig扩展过滤器,用于按条目字段对条目数组(对象或数组)进行排序。
从版本0.1.5开始,Doctrine集合可以无需手动提取数组即可直接进行排序。
安装
使用composer
composer require snilius/twig-sort-by-field
用法
列表可能看起来像这样,但显然每个数组中有多于一个键。
$base = array(
array(
"name" => "Redmine"
),
array(
"name" => "GitLab"
),
array(
"name" => "Jenkins"
),
array(
"name" => "Piwik"
)
);
{% for item in base | sortbyfield('name') %}
{{ item.name }}
{% endfor %}
对于Symfony的用法,您需要将其添加为服务并标记为Twig。
# app/config/services.yml
services:
twig.extension.sortbyfield:
class: Snilius\Twig\SortByFieldExtension
tags:
- { name: twig.extension }
许可协议
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
https://apache.ac.cn/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.