| 1 |
--- |
| 2 |
title: HasPrev |
| 3 |
description: Reports whether there is a pager before the current pager. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: bool |
| 9 |
signatures: [PAGER.HasPrev] |
| 10 |
--- |
| 11 |
|
| 12 |
Use the `HasPrev` method to build navigation between pagers. |
| 13 |
|
| 14 |
```go-html-template |
| 15 |
{{ $pages := where site.RegularPages "Type" "posts" }} |
| 16 |
{{ $paginator := .Paginate $pages }} |
| 17 |
|
| 18 |
{{ range $paginator.Pages }} |
| 19 |
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2> |
| 20 |
{{ end }} |
| 21 |
|
| 22 |
{{ with $paginator }} |
| 23 |
<ul> |
| 24 |
{{ with .First }} |
| 25 |
<li><a href="{{ .URL }}">First</a></li> |
| 26 |
{{ end }} |
| 27 |
{{ if .HasPrev }} |
| 28 |
<li><a href="{{ .Prev.URL }}">Previous</a></li> |
| 29 |
{{ end }} |
| 30 |
{{ if .HasNext }} |
| 31 |
<li><a href="{{ .Next.URL }}">Next</a></li> |
| 32 |
{{ end }} |
| 33 |
{{ with .Last }} |
| 34 |
<li><a href="{{ .URL }}">Last</a></li> |
| 35 |
{{ end }} |
| 36 |
</ul> |
| 37 |
{{ end }} |
| 38 |
``` |
| 39 |
|
| 40 |
You can also write the above without using the `HasPrev` method: |
| 41 |
|
| 42 |
```go-html-template |
| 43 |
{{ $pages := where site.RegularPages "Type" "posts" }} |
| 44 |
{{ $paginator := .Paginate $pages }} |
| 45 |
|
| 46 |
{{ range $paginator.Pages }} |
| 47 |
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2> |
| 48 |
{{ end }} |
| 49 |
|
| 50 |
{{ with $paginator }} |
| 51 |
<ul> |
| 52 |
{{ with .First }} |
| 53 |
<li><a href="{{ .URL }}">First</a></li> |
| 54 |
{{ end }} |
| 55 |
{{ with .Prev }} |
| 56 |
<li><a href="{{ .URL }}">Previous</a></li> |
| 57 |
{{ end }} |
| 58 |
{{ with .Next }} |
| 59 |
<li><a href="{{ .URL }}">Next</a></li> |
| 60 |
{{ end }} |
| 61 |
{{ with .Last }} |
| 62 |
<li><a href="{{ .URL }}">Last</a></li> |
| 63 |
{{ end }} |
| 64 |
</ul> |
| 65 |
{{ end }} |
| 66 |
``` |