๐ Pagination Bar
Last updated๏ผ2026-11-25
Previous / next / page numbers at the bottom of list pages. Works with the list function or built-in list pages.
โก Simplest Form
Calling {{pagebar .TotalPages .CurrentQuery .CurrentPage}} in a template generates previous / next / page number links, but it is based on the ?page=N query parameter. โ ๏ธ Only suitable for purely dynamic sites without a CDN; platform public pages and tenant sites behind CDN / edge caching should use the path-style fields below.
<div class="pagination">
{{pagebar .TotalPages .CurrentQuery .CurrentPage}}
</div>
๐ Pagination-related Fields
When using list pagination or built-in list pages, the following fields are available:
- {{.Page}} Current page โ number
- {{.TotalPages}} Total pages โ number
- {{.TotalItems}} Total items โ number
- {{.HasPrev}} Whether there is a previous page โ boolean
- {{.HasNext}} Whether there is a next page โ boolean
- {{.PrevPage}} Previous page number โ number
- {{.NextPage}} Next page number โ number
- {{.PageNumbers}} Page number array; each item contains .Num (page number), .URL (path-style link), .IsEllipsis (whether it is an ellipsis placeholder) โ array
- {{.FirstURL}} First page link (path-style, no ?, friendly to full-site static export) โ URL
- {{.PrevURL}} Previous page link (path-style) โ URL
- {{.NextURL}} Next page link (path-style) โ URL
- {{.LastURL}} Last page link (path-style) โ URL
- {{.PageBase}} Base path of the current pagination (the root of path-style pagination, e.g. /products), handy for assembling custom links โ URL
Two pagination link styles coexist: pagebar and pageURL generate ?page=N query-style links (legacy dynamic approach); FirstURL/PrevURL/NextURL/LastURL/PageNumbers[].URL are path-style links (e.g. /products/index2.html). Always use path-style by default: CDN / edge cache keys usually only consider the path and drop queries, so query-style pagination behind a cache flips to the same page every time. Only purely dynamic sites confirmed to have no CDN and no static export should use query-style.
๐ป Custom Pagination Bar (Recommended: path-style, friendly to full-site static export)
The system has already computed the path-style link (no ?) for each button โ just output it; use .Num / .URL / .IsEllipsis from PageNumbers to render page numbers.
<div class="pagination">
{{if .HasPrev}}<a href="{{.FirstURL}}">First</a><a href="{{.PrevURL}}">Prev</a>{{end}}
{{range .PageNumbers}}
{{if .IsEllipsis}}<span class="dots">โฆ</span>
{{else if eq .Num $.Page}}<span class="current">{{.Num}}</span>
{{else}}<a href="{{.URL}}">{{.Num}}</a>{{end}}
{{end}}
{{if .HasNext}}<a href="{{.NextURL}}">Next</a><a href="{{.LastURL}}">Last</a>{{end}}
</div>
Alternative (only for purely dynamic sites without a CDN): the pageURL function generates ?page=N links and must be given 3 arguments (current page / total pages / query string): {{pageURL .PrevPage .TotalPages .CurrentQuery}}. Before going live, confirm there is no edge cache, otherwise pagination will break.
Pagination on Platform Public Pages (unrelated to tenant templates)
The platform template marketplace, docs, and aggregation pages are always path-style with .html; do not attempt query-style pagination on these pages:
- Template marketplace:
/templates/index2.html,/templates/cat/<slug>/index2.html,/templates/tag/<slug>/index2.html,/templates/search/<token>/index2.html - The first page of each filter is respectively
/templates/cat/<slug>.html,/templates/tag/<slug>.html,/templates/search/<token>.html(no?); legacy forms with?tag=/?q=have their parameters ignored and no longer filter.
CloudSite SaaS