# hasTemplate() and hasPrevListed()

**URL:** https://forum.getkirby.com/t/hastemplate-and-hasprevlisted/27307
**Category:** Questions
**Tags:** v3
**Created:** [December 15, 2022, 2:04pm UTC](https://forum.getkirby.com/t/hastemplate-and-hasprevlisted/27307 "2022-12-15T14:04:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![LordCanis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lordcanis/32/16516_2.png) [@LordCanis](https://forum.getkirby.com/u/LordCanis)
#### Post date: [December 15, 2022, 2:04pm UTC](https://forum.getkirby.com/t/hastemplate-and-hasprevlisted/27307/1 "2022-12-15T14:04:46Z")

</div>

Hey,

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

```auto
<?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.

---

<div class="post-metadata">

### Author: ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)
#### Post date: [December 15, 2022, 2:20pm UTC](https://forum.getkirby.com/t/hastemplate-and-hasprevlisted/27307/2 "2022-12-15T14:20:19Z")

</div>

See [$page-\>hasPrevListed() | Kirby CMS](https://getkirby.com/docs/reference/objects/cms/page/has-prev-listed) how to pass a collection as param

---

<div class="post-metadata">

### Author: ![LordCanis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lordcanis/32/16516_2.png) [@LordCanis](https://forum.getkirby.com/u/LordCanis)
#### Post date: [January 19, 2023, 10:46am UTC](https://forum.getkirby.com/t/hastemplate-and-hasprevlisted/27307/3 "2023-01-19T10:46:03Z")

</div>

Thank you very much.

This is how it works for me:

```auto
<?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 ?>

```

---

<div class="post-metadata">

### Author: ![rasteiner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rasteiner/32/4788_2.png) [@rasteiner](https://forum.getkirby.com/u/rasteiner)
#### Post date: [January 19, 2023, 11:10am UTC](https://forum.getkirby.com/t/hastemplate-and-hasprevlisted/27307/4 "2023-01-19T11:10:13Z")

</div>

You can also do:

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

```

Slightly less verbose…

---

<div class="post-metadata">

### Author: ![LordCanis](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lordcanis/32/16516_2.png) [@LordCanis](https://forum.getkirby.com/u/LordCanis)
#### Post date: [January 19, 2023, 11:13am UTC](https://forum.getkirby.com/t/hastemplate-and-hasprevlisted/27307/6 "2023-01-19T11:13:22Z")

</div>

🙏 Thank you!!!
