Skip to content
Discussion options

You must be logged in to vote

Normally I'd just suggest that getFilteredByTags API and maybe a loop, and maybe something like this:

  const tagMap = {
    _carrots: ["vegetable", "carrot"],
    _tomatoes: ["tomato"],
    _vegetables: ["carrot", "tomato"], // returns 0 records since no pages have both "carrot" AND "tomato" as tags.
  };

  for (const [name, tags] of Object.entries(tagMap)) {
    eleventyConfig.addCollection(name, collectionApi => collectionApi.getFilteredByTags(...tags));
  }

Or, another option if you want to dynamically query collections is maybe a hack like this (which might be a terrible idea, but seems to work):

eleventyConfig.addCollection("dynamic", collectionApi => collectionApi);

And then you c…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
3 replies
@j9t
Comment options

@pdehaan
Comment options

pdehaan Dec 13, 2022
Collaborator

@j9t
Comment options

Answer selected by j9t
Comment options

You must be logged in to vote
4 replies
@j9t
Comment options

@nhoizey
Comment options

@j9t
Comment options

@nhoizey
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants