11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
16.84k stars 487 forks source link

using `alias: page` in pagination throws error #1794

Open andyford opened 3 years ago

andyford commented 3 years ago

given this frontmatter pagination setup:

---
pagination:
    data: pages
    size: 1
    alias: page
permalink: "{{ page.slug | slug }}/"
layout: layouts/base.njk
---

Eleventy will throw the following error:

> mapB.date.getTime is not a function

`TypeError` was thrown:
    TypeError: mapB.date.getTime is not a function

This appears to be because of using the name page in alias: page.

It would be great to support alias: page without issue, but if that's not feasible, it would be nice to add this caveat to the documentation.

pdehaan commented 3 years ago

Ah... Yeah, page has somewhat of a special meaning in 11ty. See https://www.11ty.dev/docs/data-eleventy-supplied/.

Probably easiest to choose a slightly different alias name to avoid conflicts with the built-in page variable.

andyford commented 3 years ago

Probably easiest to choose a slightly different alias name to avoid conflicts with the built-in page variable.

... right but my suggestion is to either support alias: page or at least call out this caveat in the docs. Otherwise more poor souls will lose time and hair over this as the error message isn't particularly helpful

andyford commented 3 years ago

created a PR on the eleventy doc site to document this caveat https://github.com/11ty/11ty-website/pull/1073

paulshryock commented 3 years ago

I also ran into this same issue recently, and couldn't figure out why I was getting the date function error, for like a week. Changing page to item fixed it.

Definitely documentation for this would be great, but I'd also love to see a console error explaining the real problem.