Can i filter the result of $page->prev()?

Hi,

can i filter the result of $page->perv() / $page->next().

I start with the starterkit. And i have modifyed the note blueprint so i have now a additional field called tripname. Now i want modify the snippet prevnext.php that in the footer of a note Page only display the prev/next note with the same tripiname

This is one part of the original snippet:

    <?php if ($prev = $page->prevListed()): ?>
    <?php snippet('note', ['note' => $prev, 'excerpt' => false])  ?>
    <?php endif ?>

what must i change in the first line to filter the set of Pages?

Martin

$page->prev() returns a single page, i.e. the next page or previous page of the current page, you can only filter a pages collection? Not quite sure what you want to achieve here.

However, you can pass the relevant filtered pages collection within which you want to search for the next page as an argument to $prevListed:

For example:

<?php $myFilterPages = $page->children()->listed()->filterBy('tripname', 'sometrip'); ?>

<?php if ($prev = $page->prevListed($myFilterPages)): ?>
    <?php snippet('note', ['note' => $prev, 'excerpt' => false])  ?>
<?php endif ?>

Ok, I’ll try to explain it better again.

I have a page type “note” (blueprint note.yml). Each of these pages contains a daily report of a trip. The page has a field called tripname. All daily reports of the same trip have the same tripname.
In the footer of each daily report I would like to switch to a daily report of the same trip with prev/next.

I’ll take a look at your suggestion with the Collection. Thanks

Martin

Since you need the sibling pages, change the $myFilterPages variable to:

<?php $myFilterPages = $page->siblings()->listed()->filterBy('tripname', 'sometrip'); ?>

And the hardcoded sometrip to the tripname of the current page.

thanks … it works fine!