proxy.golang.org : github.com/muhlemmer/pagination
Package pagination provides a convenient way to set up a pagination range with data for use in a "html/template". It places the current page on a defined position (while preventing overflows). There is a maximum size of the pagination, to fit your template design when the result set grows. For convenience it provides all necessary data, like next, prev and current page easily called from the pagination methods inside the template. Usage: Naturally, "Pos" should always be smaller than "Max". "Page" should always be smaller than (Total / Size = Pages), rounded up. "Records" can never be bigger than "Size" and "Total". "Records" is usually equal to Size, but can be smaller on the last page in practice. "Records" value is not used in any calculation and can be omitted if not needed in the template for example statistics. All the constraints are checked during creation of the new pagination object: Now the Pagination object pointer can be incorporated in the data structure passed to a template Let's say you use a separate template for pagination, you can call it from a layout template like: Finally, inside the pagination template simply call the methods where you need them. ".Entries" gives the actual pagination range. Every "Entry" has two fields, "Active" and "Number": "Active" is set to boolean true if that Entry represents the current page. False for all others. So a direct test can be done unsing {{if .Active}}. "Number" is set to the number the pagination entry is referring to. All the other methods just print a number for statistical puposes.
Registry
-
Source
- Documentation
- JSON
- codemeta.json
purl: pkg:golang/github.com/muhlemmer/pagination
License: BSD-3-Clause
Latest release: over 7 years ago
First release: over 7 years ago
Namespace: github.com/muhlemmer
Stars: 2 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: about 2 months ago