Get index of page in collection?

Is it possible to easily get the index of a page within a given collection?

Not quite the same as $page->num(), because if you have the pages set to be numbered by date, you’ll get 20160101, and also because there’ the issue of where do the invisible items end up in the collection…

Two things: if you only want the visible items in your collection, you can chain the visible() method to your call:

// Alter to your needs
$myCollection = $site->pages()->visible();

To get a index, you can loop the collection like this:

<?php foreach($myCollection as $key => $myPage): ?>
   // $key is your index :)
<?php endforeach ?>

Try

$pages->indexOf('some-page'); 

thanks @texnixe, I didn’t think to look in the Toolkit docs. This does the trick!