benoitD
February 10, 2019, 6:49pm
1
Hey All !
I am wondering if there is a way to handle dynamic routing for static pages in Ghost ?
I have multiple static pages that I’d like to group under the same base url.
example :
https://www.mywebsite/glossary/first-definition
https://www.mywebsite/glossary/second-definition
https://www.mywebsite/glossary/third-definition
In the above example, I have 3 static pages : “first-definition” ; “second-definition” and “third-definition”.
I would like all of them to have the same base url : “https://www.mywebsite/glossary/ ”.
I know I can do this with normal posts using collection, or channels (https://docs.ghost.org/api/handlebars-themes/routing/channels/ ). However I can’t manage to do it with static pages …
Any idea on how to do it ?
Ben
Kevin
February 11, 2019, 10:20am
3
@benoitD this is absolutely possible You can configure it using the routes
section of your routes.yaml
file. Full docs are here:
Build dedicated URL structures using Ghost's dynamic routing system, for custom homepages, podcasts, categories and more.
1 Like
@Kevin is right. I removed my comment because it was wrong. I found something that is a little strange. I created routes.yaml
:
routes:
/glossary/first-definition/:
template: first-definition
data: page.first-definition
I created a page with slug first-definition
.
I duplicated page.hbs
and rename it to first-definition.hbs
.
Restarted Ghost.
The strange part was that I had to replace {{#post}}
with {{#page}}
to get the actual content from admin.
1 Like
benoitD
February 11, 2019, 2:03pm
5
Thank you very much for your help !
The solution from @HauntedThemes works great
I’m now trying to make it scalable because I may have many pages in my glossary.
Following this solution, I would have to create :
first-definition.hbs
second-definition.hbs
…
nth-definition.hbs
And routes.yaml would look like :
routes:
/glossary/first-definition/:
template: first-definition
data: page.first-definition
/glossary/second-definition/:
template: second-definition
data: page.second-definition
...
/glossary/nth-definition/:
template: nth-definition
data: page.nth-definition
I’ll dig deeper into the documentation to find a way to do this with a single .hbs
file and a single generic route (using {slug}).
I’ll come back here if I find a solution
benoitD
February 17, 2019, 5:24pm
6
I finally choose to create 2 collections in routes.yaml
.
Here is my file :
routes:
collections:
/:
permalink: /{slug}/
template: index
filter: tag:-glossary
/glossary/:
permalink: /glossary/{slug}/
template: index-glossary
filter: tag:glossary
taxonomies:
tag: /tag/{slug}/
author: /author/{slug}/
I do not create definitions as static pages anymore. They are now posts with tag: glossary. This allows me to filter out definitions from first collection.
I also created 2 new files : index-glossary.hbs
(custom page for https://mywebsite/glossary ) and custom-post-glossary.hbs
(custom template for all definitions : https://mywebsite/glossary/first-definition , https://mywebsite/glossary/second-definition , …).
I think this is a good option for anyone that would want to create a glossary using Ghost
Thank you all for your help, it helped me a lot !
2 Likes
system
Closed
March 3, 2019, 5:27pm
7
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.