Collection indexOf

Hello,

In the reference $page->indexOf() is described as…

Returns the position / index in the collection

…but collection there seems to mean all siblings of the page, and not any other particular $pages object.

For example:

<?php dump($site->children()) ?>

Kirby\Cms\Pages Object
(
    [0] => bananas
    [1] => ball-ball
    [2] => bananasssss
    [3] => socks
    [4] => mooore-bananaaas
    [5] => wurst
    [6] => error
    [7] => home
    [8] => success
)

<?php dump($site->children()->filterBy('intendedtemplate','product')) ?>

Kirby\Cms\Pages Object
(
    [0] => bananas
    [1] => ball-ball
    [2] => bananasssss
    [3] => mooore-bananaaas
    [4] => wurst
)

<?php foreach($site->children()->filterBy('intendedtemplate','product') as $product): ?>
	<?= $product->indexOf() . ' => ' . $product->title() . '<br />'?>
<?php endforeach ?>

0 => Bananas	
1 => Ball ball	
2 => Bananasssss	
4 => Mooore Bananaaas 	
5 => Wurst

Although I am looping $site->children()->filterBy('intendedtemplate','product') indexOf takes $site->children() as the reference collection.

First, is this expected and desired behaviour? and, is this what is expected from users to understand from the description of indexOf at reference page?

Second, how do I access the index of the page in the actual collection I am looping ?

Thank you

If you want to get the index of a page in relation to a particular collection, you have to pass that collection as an argument, see the documentation.

$collection = $site->children()->filterBy('intendedtemplate','product');
$index = $page->indexOf($collection);

If you don’t pass the collection as an argument, the standard non-filtered siblingscollection is the reference.