Skip to content

$pages->groupBy()

Alias for Kirby\Toolkit\Collection::group

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

Parameters

Name Type Default
$args mixed null

Return type

Kirby\Toolkit\Collection

Exceptions

Type Description
Exception

Parent class

Kirby\Cms\Pages inherited from Kirby\Toolkit\Collection

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