$pages->group()
Groups the items by a given field or callback. Returns a collection with an item for each group and a collection for each group.
$pages->group(string|Closure $field, bool $caseInsensitive = true): Kirby\Cms\Pages
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| $fieldrequired | stringorClosure |
no default value | |
| $caseInsensitive | bool |
true
|
Ignore upper/lowercase for group names |
Return type
This method does not modify the existing $pages object but returns a new object with the changes applied. Learn more →
Exceptions
| Type | Description |
|---|---|
Kirby\Exception\Exception |
Parent class
Kirby\Cms\Pages
inherited from Kirby\Cms\Collection
Examples
// 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);
});