Dynamic route triggering custom template on pagination

Kia ora!

I’ve just been working on setting up dynamic routing so I can combine my Ghost site with my portfolio site without clogging up my newsletter. I’m pretty much all set except for an odd pagination issue!

I’m self hosting, running 5.94.0 and using a modified version of Source 1.3.2.

The issue I have is that pagination on my home (/) page triggers the same home template on /page/2, showing the exact same content, rather than the index template that often triggers with other Source installs.

Here’s my routes.yaml - I’m wondering if there’s something missing to get pagination working correctly?

routes:

collections:
  /:
    template: home
    permalink: /newsletter/{slug}/
    filter: primary_tag:newsletter
  /art/:
    permalink: /art/{slug}/
    template: collection
    filter: primary_tag:art
    data: tag.art
  /speaking/:
    permalink: /speaking/{slug}/
    template: collection
    filter: primary_tag:speaking
    data: tag.speaking
  /essays/:
    permalink: /essays/{slug}/
    template: collection
    filter: primary_tag:essay
    data: tag.essay

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

home.hbs is largely unmodified from Source:

{{!< default}}
{{!-- The tag above means: insert everything in this file into the body of the default.hbs template --}}

{{> "components/header" headerStyle=@custom.header_style}}

{{#match @custom.header_style "!=" "Highlight"}}
    {{> "components/featured" showFeatured=@custom.show_featured_posts limit=4}}
{{/match}}

{{> "components/cta"}}

{{> "components/post-list" feed="home" postFeedStyle=@custom.post_feed_style showTitle=true showSidebar=@custom.show_publication_info_sidebar}}

and the only modification I’ve made otherwise is inserting a custom about-card into header-content.

Is there a way to force /page/2 to load index rather than home? Thanks in advance!

Which header style setting are you using?

Actually, humor me a second - can you remove the template setting from the / collection? I’m thinking that’ll default you over to index, but then the / route will load home… I’m hoping!

Thanks for your help! That’s done something odd - it fixes the pagination, but breaks the filtering, so now / includes all posts, not just the ones with the primary tag newsletter. I’m using the magazine header.

From memory, Source doesn’t respect routing. You’d need to edit the get requests to include your filter.

1 Like

Oh hold up - the filtering doesn’t work regardless of whether the template setting is there, so that’s a separate error I haven’t quite figured out (but would still LOVE help with).

Interestingly, with the template setting removed, the home page appears as expected (using home) but with posts not tagged newsletter, while page/2 lists only newsletter posts, but lists all of them.

Oh true! Okay that’s simple enough - thank you!

1 Like