Collections appear as empty objects in elevetyComputed #3014
Replies: 1 comment 5 replies
-
I'm not sure of the technical details of why Not sure I'm reproducing the behaviors you're explaining though (re: sync and async). beers: (data) => {
// if (Object.keys(data).length === 0) console.log({ data });
console.log(JSON.stringify({
beers: data.collections.beer.length,
keys: Object.keys(data).sort(),
}));
return data.collections.beer
.filter((a) => a.data.breweries.includes(data.permalink))
.sort((a, b) => parseInt(a.data.number) + parseInt(b.data.number));
}, This will log something like this locally: …
{"beers":0,"keys":[]}
{"beers":0,"keys":[]}
{"beers":828,"keys":["aliases","beers","collections","eleventy","eleventyComputed","facebook","imagePath","instagram","layout","location","meta","page","parent","permalink","pkg","seoTitle","socialMediaPhoto","stats","style","tags","title","twitter","untappd","website"]}
… But that seems to be the same behavior as when I slap an beers: async (data) => {
// if (Object.keys(data).length === 0) console.log({ data });
console.log(JSON.stringify({
beers: data.collections.beer.length,
keys: Object.keys(data).sort(),
})); |
Beta Was this translation helpful? Give feedback.
-
The issue
I am trying to access
collections
in an 11tydata.js directory data file, which setseleventyComputed
.When I access
data
from a function which generates the value for aneleventyComputed
property,collections
appears twice as an empty object.Note, there is only one template file in the directory that contains the
11tydata.js
file.The following logs two empty objects:
I tried an
asyc
function, and it logs an empty object, followed by an object containing thecollections
:Why I think the first code example should work
First, in the documentation, under Order of Operations, it states:
This seems to say that the collections are sorted out before Computed Data is processed.
Second, there is an example from a working website here, where collections are accessed without an
async
function:Questions
async
function, why doesdata.collections
log as empty?async
function, why is the firstdata.collections
empty, but the second one populated?data.collections
is logged twice, why?Beta Was this translation helpful? Give feedback.
All reactions