Reference

Guide

$pages->group()

Groups the elements by a given callback

$pages->group(Closure $callback): Kirby\Cms\Pages

Parameters

Name Type Default Description
$callback Closure

Return type

Kirby\Cms\Pages

Example

// return collection of pages grouped by the first character of their title field
$groups = $page->children()->sortBy('title', 'asc')->group(function($item) {
    return Str::substr($item->title()->value(), 0, 1);
});

More information

Grouping collections

Inherited from

Kirby\Toolkit\Collection

Source code

kirby/src/Toolkit/Collection.php#L487