Standard data model for individual templates, items in a collection, pages in pagination (👍35) #3984
Replies: 15 comments
This comment has been hidden.
This comment has been hidden.
-
|
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 |
Beta Was this translation helpful? Give feedback.
-
|
Per #280, I'd really like if paginated pages exposed the key of the thing currently being iterated. |
Beta Was this translation helpful? Give feedback.
-
|
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! |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
It's been a while since I looked at it, but I think |
Beta Was this translation helpful? Give feedback.
-
|
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 |
Beta Was this translation helpful? Give feedback.
-
|
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? |
Beta Was this translation helpful? Give feedback.
-
|
@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 |
Beta Was this translation helpful? Give feedback.
-
|
Really hoping to see this breaking change make an appearance in upcoming betas for v1.0 😉 |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
To add to my confusion there also is |
Beta Was this translation helpful? Give feedback.
-
|
FWIW, since I was looking at this the other day… |
Beta Was this translation helpful? Give feedback.
-
|
Ah, thank you ❤️ |
Beta Was this translation helpful? Give feedback.
-
|
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 |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Per @paulrobertlloyd documentation:
page.urlitem.urlshould beitem.page.urlpage.dateitem.dateshould beitem.page.datepage.inputPathitem.inputPathshould beitem.page.inputPathpage.outputPathitem.outputPathshould beitem.page.outputPathpage.fileSlugitem.fileSlugshould beitem.page.fileSlugcontentorlayoutContent(only available in layouts)item.templateContentshould beitem.contenttitleitem.data.titleshould beitem.titlefoobaritem.data.foobarshould beitem.foobarhttps://www.11ty.io/docs/collections/#individual-collection-items-(useful-for-sort-callbacks)
Beta Was this translation helpful? Give feedback.
All reactions