Reference

Guide

$pages->groupBy()

Alias for Kirby\Toolkit\Collection::group

$pages->groupBy($args = null): Kirby\Toolkit\Collection

Parameters

Name Type Default Description
$args null

Return type

Kirby\Toolkit\Collection

Exceptions

Type Description
Exception

Example:

<?php
$years = page('projects')->children()->groupBy('year');
foreach($years as $year => $items): ?>
    <h2><?= $year ?></h2>
    <ul>
      <?php foreach($items as $item) : ?>
      <li><?= $item->title() ?></li>
      <?php endforeach; ?>
    </ul>
<?php endforeach ?>

More information

Grouping collections

Inherited from

Kirby\Toolkit\Collection

Source code

kirby/src/Toolkit/Collection.php#L592