Page route for homepage, and blog issue

Hi, I’m running the latest 2.x release, and trying to figure out the dynamic routing feature.

Basically, I want a ‘page’ with slug ‘home’ to appear as the homepage on root (/), and blog posts under /blog/, but for the homepage only a blank template renders (although a page with slug ‘home’ exists), and the blog renders without a header.

Here’s the routes.yaml:

routes:
  /:
    data: page.home
    template: index

collections:
  /blog/:
    permalink: /blog/{slug}/
    template: tag

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

Any ideas on how to fix these two issues?

Thanks!

1 Like

@vicnick I think the problem is your use of index as your homepage template.

routes:
  /:
    data: page.home
    template: index

Will render the index.hbs template but only make {{page}} available which is unlikely to work because index.hbs typically expects {{posts}}.

What you could try instead is specifying your page.hbs template to be used:

routes:
  /:
    data: page.home
    template: page

Or alternatively, you could create a completely custom home page (bear in mind you’ll still only have access to {{page}} in the template due to the way the data: attribute works):

routes:
  /:
    data: page.home
    template: home
1 Like

Thanks for your suggestions Kevin.

Setting the template to page didn’t work either. It renders the page with a header and footer but no page content in between, although a page with slug home exists with content (otherwise accessible as /home just fine).

Has anyone tried something like this before, to basically have a static homepage?!

I think the problem is that the data: page.home attribute makes the resource available as {{page}} and not as {{post}} and that’s why you are seeing a blank page. This is the default behaviour - Ghost uses the resource type (in this case “page”) as name for the theme object.

If you would use this notation, it should work.

routes:
  /:
    data:
      post: page.home
    template: page

Or you have to use {{page}} in your template.

1 Like

Thanks Kate. That explains it, and works the way you’ve noted, as well as setting data to post even though the content is a page:

routes:
  /:
    data: post.home
    template: page

Yet the header is not displayed in either case. I’m using plain-stock Ghost templates, without any mods.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.