From faacf2e971c44f8c7eb98f88aef4192fe866e189 Mon Sep 17 00:00:00 2001 From: Andrew Medworth Date: Wed, 16 Sep 2020 11:19:54 +0100 Subject: [PATCH] Clarify pagination documentation (#1208) * Clarify pagination documentation (#7609) It is not necessary that the pages passed to .Paginate be a subset of .Pages. Also, clarify that more than one call to .Paginator or .Paginate will give unexpected results. * Correct a few statements based on review feedback --- content/en/templates/pagination.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/content/en/templates/pagination.md b/content/en/templates/pagination.md index bd4176761..5c20f8ad0 100644 --- a/content/en/templates/pagination.md +++ b/content/en/templates/pagination.md @@ -43,10 +43,16 @@ Setting `Paginate` to a positive value will split the list pages for the homepag There are two ways to configure and use a `.Paginator`: 1. The simplest way is just to call `.Paginator.Pages` from a template. It will contain the pages for *that page*. -2. Select a subset of the pages with the available template functions and ordering options, and pass the slice to `.Paginate`, e.g. `{{ range (.Paginate ( first 50 .Pages.ByTitle )).Pages }}`. +2. Select another set of pages with the available template functions and ordering options, and pass the slice to `.Paginate`, e.g. + * `{{ range (.Paginate ( first 50 .Pages.ByTitle )).Pages }}` or + * `{{ range (.Paginate .RegularPagesRecursive).Pages }}`. For a given **Page**, it's one of the options above. The `.Paginator` is static and cannot change once created. +If you call `.Paginator` or `.Paginate` multiple times on the same page, you should ensure all the calls are identical. Once *either* `.Paginator` or `.Paginate` is called while generating a page, its result is cached, and any subsequent similar call will reuse the cached result. This means that any such calls which do not match the first one will not behave as written. + +(Remember that function arguments are eagerly evaluated, so a call like `$paginator := cond x .Paginator (.Paginate .RegularPagesRecursive)` is an example of what you should *not* do. Use `if`/`else` instead to ensure exactly one evaluation.) + The global page size setting (`Paginate`) can be overridden by providing a positive integer as the last argument. The examples below will give five items per page: * `{{ range (.Paginator 5).Pages }}`