Skip to content

Commit

Permalink
Document Pager methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring authored Jun 9, 2024
1 parent 015049a commit c5c6aa7
Show file tree
Hide file tree
Showing 16 changed files with 600 additions and 0 deletions.
44 changes: 44 additions & 0 deletions content/en/methods/pager/First.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: First
description: Returns the first pager in the pager collection.
categories: []
keywords: []
action:
related:
- methods/pager/Last
- methods/pager/Prev
- methods/pager/Next
- methods/pager/HasPrev
- methods/pager/HasNext
- methods/page/Paginate
returnType: page.Pager
signatures: [PAGER.First]
---

Use the `First` 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 }}
{{ 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 }}
```
72 changes: 72 additions & 0 deletions content/en/methods/pager/HasNext.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 }}
```
72 changes: 72 additions & 0 deletions content/en/methods/pager/HasPrev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
title: HasPrev
description: Reports whether there is a pager before the current pager.
categories: []
keywords: []
action:
related:
- methods/pager/HasNext
- methods/pager/Prev
- methods/pager/Next
- methods/pager/First
- methods/pager/Last
- methods/page/Paginate
returnType: bool
signatures: [PAGER.HasPrev]
---

Use the `HasPrev` 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 `HasPrev` 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 }}
```
44 changes: 44 additions & 0 deletions content/en/methods/pager/Last.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: Last
description: Returns the last pager in the pager collection.
categories: []
keywords: []
action:
related:
- methods/pager/First
- methods/pager/Prev
- methods/pager/Next
- methods/pager/HasPrev
- methods/pager/HasNext
- methods/page/Paginate
returnType: page.Pager
signatures: [PAGER.Last]
---

Use the `Last` 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 }}
{{ 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 }}
```
44 changes: 44 additions & 0 deletions content/en/methods/pager/Next.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: Next
description: Returns the next pager in the pager collection.
categories: []
keywords: []
action:
related:
- methods/pager/Prev
- methods/pager/HasPrev
- methods/pager/HasNext
- methods/pager/First
- methods/pager/Last
- methods/page/Paginate
returnType: page.Pager
signatures: [PAGER.Next]
---

Use the `Next` 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 }}
{{ 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 }}
```
25 changes: 25 additions & 0 deletions content/en/methods/pager/NumberOfElements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: NumberOfElements
description: Returns the number of pages in the current pager.
categories: []
keywords: []
action:
related:
- methods/pager/TotalNumberOfElements
- methods/page/Paginate
returnType: int
signatures: [PAGER.NumberOfElements]
---

```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 }}
{{ .NumberOfElements }}
{{ end }}
```
29 changes: 29 additions & 0 deletions content/en/methods/pager/PageGroups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: PageGroups
description: Returns the page groups in the current pager.
categories: []
keywords: []
action:
related:
- methods/page/Paginate
returnType: page.PagesGroup
signatures: [PAGER.PageGroups]
---

Use the `PageGroups` method with any of the [grouping methods].

[grouping methods]: /quick-reference/page-collections/#group

```go-html-template
{{ $pages := where site.RegularPages "Type" "posts" }}
{{ $paginator := .Paginate ($pages.GroupByDate "Jan 2006") }}
{{ range $paginator.PageGroups }}
<h2>{{ .Key }}</h2>
{{ range .Pages }}
<h3><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h3>
{{ end }}
{{ end }}
{{ template "_internal/pagination.html" . }}
```
31 changes: 31 additions & 0 deletions content/en/methods/pager/PageNumber.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: PageNumber
description: Returns the current pager's number within the pager collection.
categories: []
keywords: []
action:
related:
- methods/pager/TotalPages
- methods/page/Paginate
returnType: int
signatures: [PAGER.PageNumber]
---

Use the `PageNumber` 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>
{{ range .Pagers }}
<li><a href="{{ .URL }}">{{ .PageNumber }}</a></li>
{{ end }}
</ul>
{{ end }}
```
24 changes: 24 additions & 0 deletions content/en/methods/pager/PageSize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: PageSize
description: Returns the maximum number of pages per pager.
categories: []
keywords: []
action:
related:
- methods/page/Paginate
returnType: int
signatures: [PAGER.PageSize]
---

```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 }}
{{ .PageSize }}
{{ end }}
```
Loading

0 comments on commit c5c6aa7

Please sign in to comment.