'Eleventy: Create "View all posts in collection" link
I'm trying to build a site in Eleventy. The site has blog posts in two collections: A and B. When I'm reading a post in the collection A, I'd like to have a link after the post content that says, "View all A posts". And when I'm reading a post in collection B, I'd like to see a "View all B posts" link.
The blog posts share the same _includes template post.html. In that template, I should be able to create an if statement in nunjucks that goes something like this:
{% if post in collections.A %}<a href="/a">View all A posts</a>
{% elif post in collections.B %}<a href="/b">View all B posts</a>
{% endif %}
That code snippet doesn't work though. Any ideas?
Solution 1:[1]
I get answer there https://www.webstoemp.com/blog/multilingual-sites-eleventy/
module.exports = function (eleventyConfig) {
eleventyConfig.addCollection("posts_en", function (collection) {
return collection.getFilteredByGlob("./src/en/posts/*.md");
});
};
module.exports = function (eleventyConfig) {
eleventyConfig.addCollection("posts_fr", function (collection) {
return collection.getFilteredByGlob("./src/fr/posts/*.md");
});
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aynur Shauerman |
