How do precompiledCollections work? #2801
Unanswered
mrmartineau
asked this question in
Q&A
Replies: 1 comment 2 replies
-
|
I think you might be right, there is likely a bug in how these collections are injected: See this: Line 387 in 05c6263 I don’t think https://www.11ty.dev/docs/collections/#declare-your-collections-for-incremental-builds |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a page that is generated by a serverless function. The sidebar on that page makes use of a collection I created. I followed the steps (outlined here) to create a json file with the information that I want:
This generates a json file that has an array of content like this:
{ "tagList": [ { "name": "javascript", "count": 45, "color": "hsla(91,40%,60%,0.6)", "path": "javascript" }, { "name": "react", "count": 32, "color": "hsla(269,40%,60%,0.6)", "path": "react" }, ] }I have passed the contents of that file to my serverless function like so:
I think that should be enough to ensure that my templates now have access to the
collections.tagListdata, but it is not available. I have also tried these to no avail:{{ tagList }}{{ page.tagList }}{{ eleventy.serverless.tagList }}{{ precompiledCollections.tagList }}Is there something else I've missed? or should the initial way have worked?
Another question I have is around the shape of the returned collection data. Does it need to formatted in a specific way? The docs here suggest that all collections need to follow a specific structure, but I've been able to use my
collections.tagListso far without any problems.I was successful in passing the data in other ways (by not using
precompiledCollections) but so far have not found a way to populate thecollections.tagListdata like I want to. These other ways use theconfigproperty on theEleventyServerlessfunction toaddGlobalDataor add a new collection withaddCollection. 11ty gave an error when I tried to overwrite the existing collection, so I created a new one.Now my template can make use of both of these:
{{ collections.tagListServerless }}{{ tagList }}🎉
But it is still of no use because my sidebar still relies on
collections.tagListwhich is defined in mybase.njktemplate.. Now, I am fairly new to 11ty so there might be something obvious that I'm missing, but I just can't see it. Please steer me in the right direction. If you interested in helping out, the repo where I'm using this is atBeta Was this translation helpful? Give feedback.
All reactions