Ghost blog not setting the right template for collection

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:

{{#post}}
  {{#has tag="course"}}
     {{> "course"}}
  {{else}}
    {{> "article"}}
  {{/has}}
{{/post}}

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:

collections:
 /blog/:
   permalink: /posts/{slug}/
   template: index
   data: tag.article
   filter: primary_tag:article
 /cursos/:
   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