Static page route with a slug to load data

Hi,

I’m trying to set up a route for my blog as follows:

The user navigates to /stores/{storeID}
Ghost uses the store.hbs template
I load some data from an external API using the storeID and render it on the page

If the user visits /stores/, I want to show a 404

I’ve tried so many permutations of the routes.yaml file, but I can’t seem to get it right. I’m not sure if it’s a route that I need, or a collection, or a channel.

Any help would be much appreciated.

Thanks,

Nile

Hey Nile, check out this topic, it might help:

Single posts are always rendered with post.hbs - that might be what’s tripping you up. The docs aren’t super explicit like this and we need to improve them a bit :)

Hi John,

Thanks for getting back to me so quick. I took a look at the link you posted, but I’m still not sure what I’m missing.

Re-reading my initial post, I probably should have made it clearer that all I’m trying to be able to do is render a single store.hbs template when the user goes to /stores/{storeID}, and be able to access that storeID parameter within the template.

I see what you’re saying about the single posts rendering from post.hbs, but it’s not a ghost post or page that I want to show, it’s just a handlebars template that I want to render. Given that, I’m not sure how I’d use the has helper, because there would be no tag to use.

Sorry if my explanation isn’t very good, it just seems to simple what I’m trying to do, but can’t figure it out from any documentation or googling.

Thanks again,

Nile

Hey Nile - no worries :slight_smile: unfortunately custom routes and Ghost in general don’t have any concept of arbitrary parameters or additional data that can be passed into them, so that probably wouldn’t be possible in the way you’re trying to do it currently.

Your best bet for this sort of usecase would probably be to use URL params and some clientside javascript?

Ghost themes are designed to be good at rendering stuff which is in Ghost, they’re not so good at (or intended to be good at) doing things with data outside of Ghost

I thought that could be the case, seems like I’ll have to think of an alternative way to do it.

I’ve no problem looking at the url in javascript to get the bit of data that I need, so that’s fine.

Is there a way to override a 404 template for a particular route? For example, can I make it so that a 404 on the /stores/ route renders a store.hbs template, and not a error-404.hbs template?

Hey Nile, did you solve this problem. I currently have the same issue. I have a custom page template, where I want to call an external API with the data from the slug like /products/{slug}, all with javascript of course.