Paginate list of records other than children
See original GitHub issueIf I want to have a page that lists all records in some complicated query, I can always write a custom model and template that directly makes that query, but this list can’t be paginated. I can also paginate the records from a complicated query with “child replacement”, by taking a model and redefining its children to be the result of that query, as documented in https://www.getlektor.com/docs/guides/categories/ . However, this replaces all the model’s old children, which it seems are no longer generated.
Example use case: I have a website that’s primarily a blog (a list of posts), but that also has some other subpages (e.g. an about page, category/tag pages). I want the root of my website to paginate the list of posts, but also for those other pages to be generated and linkable. Using child replacement on the root to replace the children with the list of blog posts, and then paginating that, doesn’t work because now the other pages are gone. Is this currently possible in Lektor?
If it doesn’t, one way I could imagine it working is to add a replaced_with
field to the pagination section that replaces only the query used for pagination.entries
. This seems somewhat inelegant as introducing two ways to do the same thing though. It’s also possible that child replacement preventing the old children from existing in the generated website isn’t intended/desirable behavior, but I haven’t really thought through the data model well enough to be sure about that.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
I think it’s used basically exactly like
replaced_with
, you specify a query of the list you want. So my blog’s front page’s data model has something like:Analogously, to paginate the category pages in the category guide I think you could just as well replace
with
So… I discovered in the code that
pagination
has a configuration optionitems
that, as far as I can tell, literally does what the title of this issue says, implemented in 2015 in https://github.com/lektor/lektor/commit/f4448f54bd51c170c85b8660991b6fb7a047adcb and https://github.com/lektor/lektor/commit/31b3d9ce988411da8974b7109ab9c25015366938. And I guess it’s documented in https://www.getlektor.com/docs/models/children/, albeit in a way that doesn’t immediately suggest its applicability for this use case; it’s just not in the guides I looked at ¯\_(ツ)_/¯