From 2ecce64781897283a44c8b3f6636fa761ef1b799 Mon Sep 17 00:00:00 2001 From: Fred Carlsen Date: Sat, 18 Nov 2017 23:08:48 +0100 Subject: [PATCH] Added group tags by letter example --- README.md | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f09a0c6..e08acd9 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,70 @@ return [ ## Using Collections +### Group tags by letter: + +Add this macro to your config: + +```php + [ + 'tagGroups' => function () { + return $this->groupBy(function ($tag) { + return substr($tag->title, 0, 1); + }); + } + ], +]; +``` + ```twig -{% set collection = [ 'str', 'Sst', 'psst' ] | collect %} -{{ dump(collection.toUpper()) }} + + + + + Document + + + + +
+
+
+

Tags

+

+ Every tag on the site. +

+
+
+
+ + +

Tag groups

+ +
+
+
    + {% set collection = craft.tags.group('media') | collect %} + {% for letter, tags in collection.tagGroups() %} +
    +

    {{ letter }}

    + + +
    + {% endfor %} +
+
+
+ + + ``` Brought to you by [Superbig](https://superbig.co)