Confused about collections

Hi! I am new here. I have read the documentation extensively relating to routing and collections but I am still confused and not able to get it to work as I want (edit: actually i got it to work while writing this, but i am still a bit confused to posting anyway).

I have a bunch of posts that are tagged with resource. Now I wanted them (and only them) to appear under mydomain.com/resources/{blablabla}.

Here was my current routes.yaml

routes:

collections:
  /:
    permalink: /{slug}/
    template: index

  /resources/:
    permalink: /resources/{slug}/
    template: index
    filter: primary_tag:resource

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

This did not work. If I went to /resources/myresource1 i was redirected to /myresource1, and furthermore /resources/not-a-resource1 was behaving the same.

I modified the yaml-file to

routes:

collections:
  /:
    permalink: /{slug}/
    template: index
    filter: primary_tag:-[resource]

  /resources/:
    permalink: /resources/{slug}/
    template: index
    filter: primary_tag:resource

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

and now it started working. Is this because the first yaml file made it so that my resource posts still belonged to the default collection? A post can only belong to one collection at the time, so i have to make sure that my filters do not in any way allow a post to end up in multiple collections? Is this the right way to think about it?

:bulb: Idea: Please add invalid configurations to the docs and give explanations to why they are invalid, this would greatly accelerate understanding for a newcomer.

Exactly. And collections are assigned in order, so your resource posts ended up in the / collection.

1 Like