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

Eleventy collections do not implicitly add date field to pages for collections to be sorted by Sortable.js #1460

Closed
siddhantyadav opened this issue Oct 18, 2020 · 4 comments
Labels
duplicate error-messaging feature: 📦 pagination Related to Eleventy’s pagination feature

Comments

@siddhantyadav
Copy link

Describe the bug
When I am adding two or more pages to Collections in Eleventy, there is a "Cannot read property 'getTime' of undefined" because there no date field automatically added through the collection which can be used by it inside Sortable.js and hence causing an error.

To Reproduce

  1. Use the below data set for building multiple eleventy pages using any .njk file, add all the pages to the collection through addAllPagesToCollections = true

let data = [
{
name: 'abc'
},
{
name:'xyz'
}
]

Expected behavior
The pages should be built and all the pages can be added to the collection.

Screenshots
image

**"Problem writing Eleventy templates: (more in DEBUG output)

Cannot read property 'getTime' of undefined

TypeError was thrown:
TypeError: Cannot read property 'getTime' of undefined"**
Error file : node_modules@11ty\eleventy\src\Util\Sortable.js:98:17)

Additional context
If you use the data set below, it works because we can explicitly add a date field and hence the pages can be built and collections can be sorted.

let data = [
{
name: 'abc',
date:'2020-10-07T19:22:49.335Z'
},
{
name:'xyz',
date:'2020-10-07T19:22:49.335Z'
}
]

@arcxyz
Copy link

arcxyz commented Oct 20, 2020

I recently got this error when I was accidentally overriding the page variable provided by eleventy on the pagination:

---
pagination:
    data: productPages
    size: 1
    alias: page
...
---

Using another name for the pagination alias solves the issue for me.

@haroldao
Copy link

haroldao commented Mar 7, 2022

I recently got this error when I was accidentally overriding the page variable provided by eleventy on the pagination:

---
pagination:
    data: productPages
    size: 1
    alias: page
...
---

Using another name for the pagination alias solves the issue for me.

Wowwww thank you 🙌🏽 (I did the same)

@pdehaan
Copy link
Contributor

pdehaan commented Mar 7, 2022

Note that while not super obvious, there is a note about that pitfall in https://www.11ty.dev/docs/pages-from-data/ (although if anybody can think of somewhere else in the documentation where that callout would be helpful, let us know).

"Note that page is a reserved word so you cannot use alias: page. Read about Eleventy’s reserved data names in Eleventy Supplied Data."

@zachleat zachleat added duplicate error-messaging feature: 📦 pagination Related to Eleventy’s pagination feature and removed needs-triage labels Jul 10, 2024
@zachleat
Copy link
Member

Duplicate of #3251 and #1173

Also #2161 (comment)

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

No branches or pull requests

5 participants