Ghost blog not setting the right template for collection

My routes.yaml collections

    permalink: /posts/{slug}/
    template: post
    data: tag.article
    filter: primary_tag:article+tag:-course
    permalink: /cursos/{slug}/
    template: course
    data: tag.course
    filter: primary_tag:course+tag:-article

The problem is: when accessing localhost:2368/cursos/{slug}/ the rendered page is based on post template and not course template.

Can someone help me?

Node: v10.13.0
Ghost-CLI version: 1.11.0
Ghost version: 2.30.2

The template file referenced in your routes.yaml file related to the “list view” of the content in question, but all individual posts are still rendered through the same post.hbs template.

If you want to have a different layout/template depending on collection, you can use the {{#has}} helper to load different code based on your filter properties. Eg:

  {{#has tag="course"}}
     {{> "course"}}
    {{> "article"}}

Which would then load templates from partials/course.hbs and partials/article.hbs respectively

You shouldn’t need the inverse filter, btw. Each post can only ever have a single primary tag, so filtering your collections on primary tag alone should be enough :slight_smile:

   permalink: /posts/{slug}/
   template: index
   data: tag.article
   filter: primary_tag:article
   permalink: /cursos/{slug}/
   template: courses
   data: tag.course
   filter: primary_tag:course

So what you would end up with here is:

  • index.hbs (list of blog posts)
    • partials/article.hbs (single blog post)
  • courses.hbs (list of courses)
    • partials/course.hbs (single course)

and the only thing you need to do to drive this functionality is to make sure the first tag on each post is either article or course

1 Like

Thank you very much for this answer, John.
It is working perfectly now!