Replies: 2 comments
-
Where the engPosts.forEach(item => {
...
}); Which means the let engPosts = collection.posts_en; Except the collection API doesn't exactly work that way in this context (even though thats how you reference them in templates). // Via https://www.11ty.dev/docs/collections/#getfilteredbytag(-tagname-)
collectionApi.getFilteredByTag("post"); Or in your case, something probably closer to this: let engPosts = collection.getFilteredByTag("posts_en");
// or maybe `collection.getFilteredByGlob("./en/posts/*.md")`, based on your snippet above. |
Beta Was this translation helpful? Give feedback.
-
Sorry for the delay in replying - I did (eventually) manage to figure out something that works Thankyou for the links: as it so happens, I had already seen them, but not delved into the
The trick to making it work was to tag the relevant posts with something that Eleventy could target when creating the collection; I use a filterTagList method (as above) to then filter out these entries once the collection is created, so that it retains only those entries that I need. It may not be elegant, but it does the job! |
Beta Was this translation helpful? Give feedback.
-
I've been playing with Eleventy over the last few weeks, and love what I see - I do however have one niggling problem I can't seem to solve! It's a bit complicated, so here goes:
Aim: I'm looking to generate tags based on posts in a specific collection, not across all collections.
Reason: I'm trying to internationalize a demo Eleventy site, with English and French language support. I've seen examples of how to create tags, such as this:
While this works very well, it does operate across all collections only - in an internationalized site, this wouldn't be practical, as we would end up with (in this case) English and French content appearing! It's for this reason I need to work out how to perform a similar task, but across one collection only.
I've been able to create a collection each for English and French posts - this is the English version:
I'm looking for something like this:
Trouble is, I know the above code doesn't work - it comes back with this error:
Is anyone able to help put me back on the straight and narrow please? I'm happy to duplicate code to cover the French equivalent of the above, as long as I can get the English version working first!
Beta Was this translation helpful? Give feedback.
All reactions