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