Prev and next links

I am using the example from the docs to have next and previous links.

  <?php if ($page->hasPrevListed()): ?>
  <a id="prev" href="<?= $page->prevListed()->url() ?>">⟵</a>
 <?php endif ?>

 <?php if ($page->hasNextListed()): ?>
 <a  id="next" href="<?= $page->nextListed()->url() ?>">⟶</a>
<?php endif ?>

My problem is the sort order is not the same (by date field) and I need to filter by template.

Have a look at the getPrev() and getNext() methods here:

They allow you to pass your collection as arguments.