Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination: add pageOnEmptyData option #1698

Merged
merged 5 commits into from
May 11, 2022
Merged

Conversation

Jaza
Copy link
Contributor

@Jaza Jaza commented Mar 18, 2021

Currently, if the data to paginate is empty, then eleventy simple generates zero pages. But you might want to always generate at least one page, and if there's no data, then perhaps show a message such as "no entries found", where the paged data would normally appear. This adds a new option pageOnEmptyData to pagination, to make such behavior possible.

@zachleat
Copy link
Member

I like this! I wonder if we can brainstorm a better name?

pageOnEmptyData? emptyDataGeneratePage? emptyDataPage?

@zachleat zachleat added the open-question Requires additional information before we can proceed. label Mar 18, 2021
@Jaza
Copy link
Contributor Author

Jaza commented Mar 18, 2021

@zachleat sure, pageOnEmptyData works for me, I struggled to come up with pageIfNoData and wasn't completely happy with it anyway.

@Jaza Jaza changed the title Pagination: add pageIfNoData option Pagination: add pageOnEmptyData option Mar 18, 2021
@zachleat zachleat added enhancement pr: enhancement and removed open-question Requires additional information before we can proceed. enhancement labels Jul 27, 2021
@zachleat zachleat merged commit 2dc653a into 11ty:master May 11, 2022
zachleat added a commit that referenced this pull request May 11, 2022
@zachleat
Copy link
Member

Merged this one (and #1698!) Went with generatePageOnEmptyData. Shipping with 2.0.0-canary.10

@bsastregx
Copy link

@zachleat I love eleventy. working on my first project I came to realize that if no posts exists on a collection where pagination is present, no page will be created, which is understandable. However, I might have a link on my global menu that points to the first page of the collection. Now that link takes the user to an inexistent page Cannot GET 'pageName' , and me (the developer) didn't have any message/warning on the terminal. Don't you think that behavior is dangerous?

Because of this I created an issue: #2928

@pdehaan suggested me to use generatePageOnEmptyData. I liked that solution. However, for any eleventy developer that does not know about generatePageOnEmptyData this behavior will be a surprise.

Now that I know about generatePageOnEmptyData my suggestion is the following:
If there is pagination && the collection is empty && generatePageOnEmptyData is not present, warn the user on the terminal. This could avoid potential undesired urls with no html.

@bsastregx
Copy link

Or maybe generatePageOnEmptyData should be true by default. To be false, developer should add generatePageOnEmptyData: false to front matter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature: 📦 pagination Related to Eleventy’s pagination feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants