Replies: 4 comments
-
Decap CMS can only read or reference your 11ty collections if they are present as folder or file collections inside your repo. As these collections are generated by 11ty programatically, they bypass your repo root and output directly to your site folder. In your case, you could create a new |
Beta Was this translation helpful? Give feedback.
-
Thanks for confirming that it can't be done using addCollection. I wanted to add this as an issue because addCollection would be a nice Eleventy function for Decap to support. I did start going down the path that you suggested creating a folder full of collection items for Decap's relation widget field to consume. What we are actually trying to do is to populate one relation field with various kinds of collections aggregated together: posts, documents, events, features, etc.. I had some success by moving my collection folders into a folder named "input" and explicitly specifying it as input and output as “_site” in .eleventy.js. This way the input folder is not added to the user’s url path to the generated html. I don't want users to see /input/ in their url. When I do it like this, any folder of collections successfully appears in the relation field drop down list. I am going to attempt to filter these results next. I like this approach because it does not require an additional “aggregatedFeaturedVisuals” folder full of njk or md items that already have a file in their respective folders (ie: posts, documents, events, features, etc..). It seemed inefficient to generate doubles of collection files just to have a folder of them aggregated. However, I would rather not change the directory structure of the local build site if I don’t have to. I have two questions since we’re on the topic of how I might solve this:
This does not work: _site/admin/config.yml
This does work, but I have to add an “input" folder and change directory structure:
This did not work: aggregatedFeaturedVisuals.json
It did populate the relation field when only one item was in the json file. Thanks so much for your help and the answer to the previous question! |
Beta Was this translation helpful? Give feedback.
-
The problem with file collections is that you cannot add new items from within the CMS as you can with folder collections. More relation examples are in the docs |
Beta Was this translation helpful? Give feedback.
-
@JG515 I converted this into a discussion as it appears to be a question rather than a feature request. |
Beta Was this translation helpful? Give feedback.
-
I added a collection using eleventyConfig.addCollection in .eleventy.js:
eleventyConfig.addCollection("featuredVisuals", function (collectionApi) {
I can output the collection to the screen in my posts.njk file:
{% for object in collections.featuredVisuals %}
{% endfor %}
However, I can't seem to get the new collection to populate a decap collection widget's relation field using config.yml:
label: "Regions"
folder: "regions"
slug: "{{slug}}"
create: true
fields:
{ label: "Layout", name: "layout", widget: "hidden", default: "layouts/region.njk" }
{ label: "Title", name: "title", widget: "string" }
{ label: "Published Title", name: "publishedTitle", widget: "string" }
{ label: "Teaser", name: "teaser", widget: "string" }
{ label: "Editorial Comments", name: "editorialComments", required: false, widget: "string" }
{ label: "Date", name: "date", widget: "date", default: "" }
{ label: "Featured Visual", name: "featuredVisual", required: false, widget: "relation", collection: "featuredVisuals", search_fields: ["title"], value_field: "{{slug}}", display_fields: ["title"], multiple: true } ||
{ label: "Post Body", name: "body", widget: "markdown" }
I believe a similar question was asked by someone else here, but no answer was given:
https://answers.netlify.com/t/cant-access-11ty-collection-from-config-yml/86307
Thanks so much for your help!
Beta Was this translation helpful? Give feedback.
All reactions