DEV Community

sjjensen
sjjensen

Posted on

2 1

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)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay