hasTemplate() and hasPrevListed()


I want to add a Prev Next navigation between pages Page 1, Page 2, Page 3.
These pages have the same template (template a)

Page tree example

  • Home
  • Page 1 (template a)
  • Page 2 (template a)
  • Page 3 (template a)
  • About
  • Contact

When i add

<?php if ($page->hasPrevListed()): ?>

the Prev Next navigation contains all pages. (from Page 1 back to Home and from Page 3 to About).

Is it possible to restrict this only to pages with template a?

Thank you.

See $page->hasPrevListed() | Kirby CMS how to pass a collection as param

Thank you very much.

This is how it works for me:

<?php $collection = $page->siblings()->listed()->filterBy('template', 'template-a'); ?>
<?php if($page->hasPrevListed($collection)): ?>
  <?= $page->prevListed($collection)->url() ?>
<?php endif ?>

<?php if($page->hasNextListed($collection)): ?>
  <?= $page->NextListed($collection)->url() ?>
<?php endif ?>

You can also do:

<?php $collection = $page->siblings()->listed()->template('template-a'); ?>

Slightly less verbose…

:pray: Thank you!!!