Collection filtering by tag

I’m am fairly new to Ghost, having some trouble getting the routes.yaml file working.

routes:
  /:
   data: 
     post: page.home
   template: home

collections:
  /portfolio/:
    permalink: /portfolio/{slug}/
    template: index
    filter: primary_tag:portfolio

  /blog/:
    permalink: /blog/{slug}/
    template: index
    filter: tag:-portfolio

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

I would expect that /portfolio would only show posts tagged “portfolio” (at least as the primary tag), and /blog would not include any portfolio posts however both routes are showing all posts.

I am using Ghost 5.85.1, this is a local set up, once I get it working I will upload it. I’ve run ghost restart after adding the new routes.yaml file just to ensure the cache is cleared.

Where might I be going wrong?

I’m going to bet a penny that you’re using Source, which doesn’t respect routing, or another theme with the same behavior. If you can inspect your theme’s source code, I’m betting you’ll find that index.hbs (or some partial that it calls) is making a {{#get "posts" .. }} request, and get requests ignore routing. A workaround would be to duplicate the index template (once per collection), and edit the get request to include filtering by tag. [Assuming you are comfortable editing the theme.] Another option would be to pick a different theme. :slight_smile:

While I’m looking at your file, I recommend that you change your blog filter to primary_tag:-portfolio because your current setup has no route assigned to a post that has a portfolio tag but not in the first slot. Or change the portfolio route to grab anything with tag:portfolio, instead.

(Aside: I don’t recognize the syntax you’re using for the /: route, but if it’s working, great!)

1 Like

Ah thank you so much! I’m using Journal, which indeed uses {{#get "posts"}}}