-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
Standard data model for individual templates, items in a collection, pages in pagination #338
Comments
This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open. The enhancement backlog can be found here: https://github.com/11ty/eleventy/issues?utf8=%E2%9C%93&q=label%3Aneeds-votes+sort%3Areactions-%2B1-desc+ Don’t forget to upvote the top comment with 👍! |
I remember I had an error where I could only get page date with ``page.data.date`. Can't remember how to reproduce this error, but I thought you should know. Didn't file an issue then. Will update again if I encounter the error. Otherwise, everything else looks good! :D |
Per #280, I'd really like if paginated pages exposed the key of the thing currently being iterated. |
Per https://mobile.twitter.com/zachleat/status/1148228091703152640 it might be nice to also expose the inputContent of the template in both I believe this might be already on the issue somewhere but was unable to track it down in a search. If someone finds it please link it up! |
It's been a while since I looked at it, but I think |
I just want to mention I had a very hard time finding this information since it isn't really clear from the docs that custom My troubles were further increased by not being able to json stringify many of the data structures inside the template because of circular references. Otherwise I normally just use So essentially, as a first time user, I had to do a LOT of guessing and googling until I finally found this page |
I have an additional use case for having a consistent/predictable data model for page frontmatter data. I’m trying to create pages from data. I have a global data file that contains an array of data, then formats this in way that reflects the page data model used internally by 11ty: const slugify = require('@sindresorhus/slugify');
module.exports = function () {
const things = [{
title: 'Foo',
summary: 'Bar.'
}, {
title: 'Baz',
summary: 'Qux.'
}];
return things.map(thing => {
const fileSlug = slugify(thing.title);
return {
date: new Date(),
fileSlug,
url: `/things/${fileSlug}`,
data: {
layout: 'thing',
title: thing.title,
summary: thing.summary
}
};
});
}; This provides following data object for each item: {
date: '2020-03-23T09:17:41.270+0000',
fileSlug: 'foo',
url: '/things/foo',
data: {
layout: 'thing',
title: 'Foo',
summary: 'Bar'
}
} I can create pages by paginating over this data, and give each item in the pagination array the alias ---
layout: thing
title: Thing
pagination:
data: things
size: 1
alias: page
permalink: "projects/things/{{ page.fileSlug }}.html"
---
This means in my templates I can call the following variables:
However, for pages not created this way, I need to use the following variables:
Might it be an idea to maintain the shorter variables for frontmatter data (e.g. This would also maintain consistency with how you loop over collection items; you can’t use Does this make any sense? |
@zachleat I think this issue is closely related to computed data, at least from my experience. Much of my use of computed data is an attempt to expose a predictable and consistent API for templates; were that already the case, my use of this new feature would be solely for computing data, not reassigning values. I say this having now found myself with a variable in my templates called |
Really hoping to see this breaking change make an appearance in upcoming betas for v1.0 😉 |
To add to my confusion there also is |
FWIW, since I was looking at this the other day… |
Ah, thank you ❤️ |
Some work will ship on this with #1522 (you can see those changes better defined in #2695) but I would consider the inconsistency in collection items that data is not available at the top level as properties to be one of the last remaining items here. https://www.11ty.dev/docs/collections/#collection-item-data-structure |
Per @paulrobertlloyd documentation:
page.url
item.url
should beitem.page.url
page.date
item.date
should beitem.page.date
page.inputPath
item.inputPath
should beitem.page.inputPath
page.outputPath
item.outputPath
should beitem.page.outputPath
page.fileSlug
item.fileSlug
should beitem.page.fileSlug
content
orlayoutContent
(only available in layouts)item.templateContent
should beitem.content
title
item.data.title
should beitem.title
foobar
item.data.foobar
should beitem.foobar
https://www.11ty.io/docs/collections/#individual-collection-items-(useful-for-sort-callbacks)
The text was updated successfully, but these errors were encountered: