Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eleventyImport, a front matter configuration option to declare template dependency #975

Closed
zachleat opened this issue Feb 28, 2020 · 9 comments
Labels
enhancement: favorite Vanity label! The maintainer likes this enhancement request a lot. enhancement feature: 🥝 incremental builds

Comments

@zachleat
Copy link
Member

zachleat commented Feb 28, 2020

We attempt to glean template dependencies automatically to process templates in the correct order but as an escape hatch this might be nice.

@zachleat zachleat added enhancement needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved. labels Feb 28, 2020
@zachleat
Copy link
Member Author

zachleat commented Feb 28, 2020

This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open.

View the enhancement backlog here. Don’t forget to upvote the top comment with 👍!

@zachleat zachleat added the enhancement: favorite Vanity label! The maintainer likes this enhancement request a lot. label Jun 15, 2022
@zachleat zachleat removed the needs-votes A feature request on the backlog that needs upvotes or downvotes. Remove this label when resolved. label Dec 16, 2022
@zachleat
Copy link
Member Author

zachleat commented Dec 16, 2022

eleventyImport.collections is an Array of collection or tag names used by the template. This is used to inform both --incremental builds and template build order.

Just as an example, say your blog index page iterates over collections.posts. If you add eleventyImport.collections: ["posts"] to the blog index page data (somewhere in the data cascade), it will rebuild the index page when any of your blog posts are changed.

Shipping with 2.0.0-canary.21

(Renamed for canary 21)

@zachleat zachleat added this to the Eleventy 2.0.0 milestone Dec 16, 2022
@zachleat zachleat changed the title Front matter configuration option to declare template dependency eleventyImportCollections, a front matter configuration option to declare template dependency Dec 16, 2022
zachleat added a commit to 11ty/11ty-website that referenced this issue Dec 16, 2022
@zachleat
Copy link
Member Author

Docs building to https://www.11ty.dev/docs/data-configuration/ (they point back here for now, sorry!)

@zachleat zachleat changed the title eleventyImportCollections, a front matter configuration option to declare template dependency eleventyImport, a front matter configuration option to declare template dependency Dec 19, 2022
@megheaiulian
Copy link

megheaiulian commented Jan 19, 2023

Does this support collections added in config with addColection ?
According to the docs we should be able to set anything in it.
if we use:

  config.addCollection("homeSections", async (collection) =>
    collection.getFilteredByGlob("./src/home/**/*").reduce(
      (map, i) => ({
        ...map,
        [i.data.type]: [...(map[i.data.type] ?? []), i],
      }),
      {}
    )
  );

is it then possible to use eleventyImport.collections: ["homeSections"] where needed ?

@zachleat
Copy link
Member Author

@megheaiulian yes exactly—I would expect collection names added via eleventyConfig.addCollection to be eligible there!

@zachleat
Copy link
Member Author

@megheaiulian
Copy link

I've tried the example above and had problems with circular dependencies when trying to loop thru a collections.homeSections.services structure in a item of type service('collections.homeSections.service').
It seems to work thou when using collections.services instead.
That homeSections is supposed to be just some syntax sugar to differentiate the purpose of the collections.

@megheaiulian
Copy link

Ah in the end what fixed my problem was eleventyExcludeFromCollections.

@monochromer
Copy link
Contributor

monochromer commented Jul 11, 2023

I have collection, created with addCollection:

// eleventy.config.js

eleventyConfig.addCollection('articles', (collectionAPI) => {
  return collectionAPI.getFilteredByGlob('src/articles/*/*.md')
})

and data file for article template, that uses collection articles for pagination:

// src/pages/article/article.11tydata.js

module.exports = {
  layout: 'base',

  pagination: {
    data: 'collections.articles',
    size: 1,
    alias: 'article'
  },

  eleventyImport: {
    collections: ['articles']
  }
}

when i change md-file, template doesn't render in incremental mode:

[11ty] File changed: src/articles/one/index.md
[11ty] Wrote 0 files (skipped 32) in 0.03 seconds (v2.0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement: favorite Vanity label! The maintainer likes this enhancement request a lot. enhancement feature: 🥝 incremental builds
Projects
None yet
Development

No branches or pull requests

3 participants