0

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!

1 Answer 1

0

The collection featuredVisual must be a Decap CMS collection - probably a folder collection. The relation field is meant to relate Decap CMS collections not 11ty collections.

Not the answer you're looking for? Browse other questions tagged or ask your own question.