DEV Community

sjjensen
sjjensen

Posted on

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 %}
Enter fullscreen mode Exit fullscreen mode

That code snippet doesn't work though. Any ideas?

Top comments (0)