Show pages similar to posts in index.hbs

So here’s what I’m trying to achieve:

https://mydomain.com/topic
https://mydomain.com/topic/subtopic1
https://mydomain.com/topic/subtopic2
https://mydomain.com/topic/subtopic3

with each of them being an article/post.

What I’ve been able to do so far:

I was able to achieve this url format using routes.yml:

collections:
  /topic/all/:
    permalink: /topic/{slug}/
    template: index
    filter: primary_tag:topic

Now, in order to have an article in https://mydomain.com/topic, I simply created a new page with the contents that should go in there.

Where I am stuck at:
I’ve got the routes to work properly. However, when I went to https://mydomain.com/topic/all I only see posts that fir the conditions. Is there any way that I can get the page I created to show up?

Theme I am editing: Casper

Hey,

Did you set the correct primary tag (this is the first tag in the list) in the new page you created?
Are you trying to set up several collections that divide your site content up into different topics?

Collections are a filtered subset of content on your site - so the collection index page will only show posts that match the filter criteria. A post can also only exist in one collection. If you need something more flexible then you might want to use channels instead.

I’d recommend reading through the routing docs which gives lots of example use cases.

Hey there, Kym!

Page has the right primary tag set, which is why I am really puzzled. :thinking:

All my posts/page have only one primary tag. I just had a look at what channels does and I don’t think I’ll need it right now.

If I have to point you to an example of what I am trying to achieve, that’d be Moz’s beginner’s guide to SEO.

  1. There will be a hub page that will give a summary of what the topic is about - which will be in URL https://mydomain.com/topic created as a page.

  2. There will be several articles that will all go in detail about the said topic - which will be in the URL https://mydomain.com/topic/subtopic1.

  3. There will be an index page in the URL https://mydomain.com/topic/all that will show both https://mydomain.com/topic and https://mydomain.com/topic/subtopic1 as an index.

I’ve managed to do all three of them. But since the post in https://mydomain.com/topic is sitting as a page and not as a post, they aren’t coming up on the index page.

Is there something that I need to add in the index.hbs to say “also show this page”?

Ah ok that example makes it clearer :+1:

To correct my previous message, you can’t use pages in a collection, only posts. So this is why it is not working for you!

Pages can be used to populate a route using the data property as explained here.

To recreate the Moz example using collections you could use the following:

collections:
  /beginners-guide-to-seo/:
    permalink: /beginners-guide-to-seo/{slug}/
    template: guide
    filter: primary_tag:guide

You’d use the template file guide.hbs to build your index page, including the summary of what the topic is about (this content would be static). Then you’d use posts to create each of the articles with a primary tag of guide.

Aaah, gotcha. Thanks for getting back to me on this, Kym. Appreciate it! :slight_smile:

1 Like