$pages->chunk()
Creates chunks of the same size. The last chunk may be smaller
$pages->chunk(int $size): Kirby\Cms\Pages
Parameters
Name | Type | Default | Description |
---|---|---|---|
$sizerequired | int |
no default value | Number of elements per chunk |
Return type
A new collection with an element for each chunk and a sub collection in each chunk
This method does not modify the existing $pages
object but returns a new object with the changes applied. Learn more →
Parent class
Kirby\Cms\Pages
inherited from Kirby\Toolkit\Collection
Examples
E.g. create chunks of three items per chunk:
<?php
$chunks = page('events')->children()->listen()->chunk(3);
foreach($chunks as $chunk): ?>
<div class="wrapper">
<?php foreach($chunk as $event): ?>
<article>
<h2><?= $event->title()->html() ?></h2>
</article>
<?php endforeach ?>
</div>
<?php endforeach ?>