Skip to content

Decap CMS config.yml fields cannot access collections added using Eleventy.js' addCollection function #6728

@JG515

Description

@JG515

I added a collection using eleventyConfig.addCollection in .eleventy.js:

eleventyConfig.addCollection("featuredVisuals", function (collectionApi) {

let visualsCollection = [];

let tagsArray = collectionApi.getFilteredByTags("posts");
tagsArray.forEach(element => {
    visualsCollection.push(element);
    
});

return visualsCollection;

I can output the collection to the screen in my posts.njk file:

{% for object in collections.featuredVisuals %}

    <Br>title is {{ object.data.title }}<br>

{% endfor %}

However, I can't seem to get the new collection to populate a decap collection widget's relation field using config.yml:

  • name: "regions"
    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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugcode to address defects in shipped code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions