$page->indexOf()
Returns the position / index in the collection
$page->indexOf(Kirby\Cms\Pages|null $collection = null): int|false
Parameters
Name | Type | Default |
---|---|---|
$collection | Kirby\Cms\Pages ornull |
null
|
Return types
int
orfalse
This method modifies the existing $page
object it is applied to and returns it again.
Parent class
Examples
<?php $children = $page->children()->listed(); ?>
<ul>
<?php foreach ($children as $child): ?>
<li class="<?php e(($child->indexOf($children) + 1) % 2, 'some-class', 'another-class') ?>">
<?= $child->title() ?>
</li>
<?php endforeach ?>
</ul>
This is just a constructed example. It's worth noting that for simple styling use, you could use CSS only.