Understanding Collections

I set up routing and custom collections like this:

routes:

collections:
  /:
    permalink: /article/{slug}/
    template: index
    filter: 'tag:hash-article'  
  /podcast/:
    permalink: /podcast/{slug}/
    template: index
    filter: 'tag:hash-podcast'

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

In my index.hbs file, I want to show a section with the latest articles and a section with the latest podcasts.

I have this and it works fine for articles:

<div class="gh-postfeed">
    {{#foreach posts from="6"}}
         {{> "card" page=../pagination.page }} {{!-- partials/card.hbs --}}
   {{/foreach}}
</div> 

To add posts, I add this:

<div class="gh-podcast">
 {{#get "posts" filter="tags:hash-podcast" include="authors,tags"}}
    {{#foreach posts}}
        
         {{> "card" page=../pagination.page }} {{!-- partials/card.hbs --}}
    {{/foreach}}
 {{/get}}
</div> 

That places the block, but also adds it to the articles list at the bottom. I tried to solve it by doing this:

<div class="gh-postfeed">
    {{#get "posts" filter="tags:hash-article" include="authors,tags"}}
        {{#foreach posts from="6"}}
              {{> "card" page=../pagination.page }} {{!-- partials/card.hbs --}}
        {{/foreach}}
     {{/get}}
</div> 

However that just loops 6 articles and then puts the podcast at the bottom.

What am I doing wrong?

So that routes.yaml will produce a page using the index template at /article/ that contains posts with the #article tag, and another index page at /podcast/ with the #podcast tag. Those posts will get automatically available and you can loop over them with {{#foreach}}, without needing a {{#get}}. And pagination will ‘just work’, which is nice.

You can definitely use {{#get}} to load additional posts into the index page like a latest or related section. It may be helpful in that case to use the ‘as’ syntax in your gets, like some of the examples here: Ghost Handlebars Theme Helpers: get

That’s pretty general, and maybe not what you need for help. I’m not sure I 100% understand what you’re trying to accomplish (and am being hindered by not knowing what theme this is). Can you post a clearer description of what you’re trying to accomplish (a picture would really help!) and maybe a little more of your index.hbs file that includes both of these sections in it?

1 Like

Thanks Cathy. It is making sense now. I was getting tripped up on the fact that {{get}} doesn’t do paging automatically. I also now understand routes a bit better.

I have been able to successfully create a home page with different post types filtered by internal tags.

1 Like