Reported in the forum: https://forum.ghost.org/t/when-using-dynamic-routes-meta-title-and-body-class-are-empty/3765
routes:
/page1/:
data: page.SLUG
template: page
If you use
<head>
<title>{{meta_title}}</title>
</head>
{{#page}}
{{/page}}
It always outputs the blog meta title and not the custom page meta title.
I see two problems:
the StaticRoutesRouter does not forward the correct context, see. It has to forward the resource type as well (e.g. page) if the data key was provided.
The meta title helper is not aware of the this.page context object -> data.page.
{{body_class}}
This helper also needs to respect this.page.
Code suggestion:
page = this.post && this.post.page ? {slug: this.post.slug} : this.page || false;
classes.push('page-' + page.slug);
{{#page}}
{{meta_title}}
{{/page}}
Ghost: master
In the dynamic routes also the following fields are empty
β Meta Data
β Twitter Card
β Facebook Card
For example, I have these data added

But he answers me with this data.

@godofredoninja Thanks. It's for sure the same underlying problem π The helpers should respect the page context object.
Is there a chance this will be fixed in the next release? :)
@velobarplus if there's somebody from the community to pick it up and contribute a PR we'd definitely help and merge it asap ;)
@kirrg001 I'm wiling to do this, but what's up with the missing resourceType in the StaticRoutesRouter, where shuold that be used?
Also you say that key should be used for that: page if the data key was provided - what about when there is more than one data key:
routes:
data:
page:
resource: posts
type: read
slug: page1
morepages:
resource: posts
type: read
slug: page-more
tags:
resource: tags
type: browse
limit: all
what should the implementation of StaticRoutesRouter.getResourceType() return in this case?
@kirrg001 I'm wiling to do this, but what's up with the missing resourceType in the StaticRoutesRouter, where shuold that be used?
Nice π
We have to push the resource type into the context object.
e.g. resource type is "page" => context = [this.routerName, resourceType]
Also you say that key should be used for that: page if the data key was provided - what about when there is more than one data key:
If there is more than one data definition, the target url does not represent a single resource. I'd not do anything in this case and don't push the resource type.
@kirrg001 ok so if a post is turned into a page, then data.page is present here in the schema meta helper (now that page is pushed into a context).
This in turns calls getPostSchema method, but the page only contains partial data about the post; missing are
What to do in this case, should post turned into a page also fetch authors and tags so that full data is present, or should meta data in case of page skip this part ?
The static controller should probably auto include tags and authors if the resource is post | page.
But i'd suggest to create separate and small pull requests per problem π
Thanks for your help!
All issues tagged with routing have been tagged with later and closed until we prioritise working on the Routing feature again.
Just for information, workaround is described in detail in https://stackoverflow.com/a/54788950/466677
I've noticed this same issue and in my opinion, this basically makes custom routes useless βΒ at least for what I am trying to do (replacing the home page). Technically it works but it's a pain without the {{body_class}} and other parameters being set properly.
I've tried numerous ideas as a workaround but came up empty-handed each time π.
I'm π€ for someone to take point on this and get it in on one of the next releases.
Re-opening this to handle prioritisation
Some fixes landed in 2.17.0.
Further problems I see:
data: page.{slug} does not provide authors,tags by default, which "breaks" the tags helper (empty output)The areas need some love and time.
Cannot read property 'slug' of undefined
----------------------------------------
TypeError: Cannot read property 'slug' of undefined
at getPostSchema (/core/server/data/meta/schema.js:72:31)
at getSchema (/core/server/data/meta/schema.js:179:20)
at core/server/data/meta/index.js:101:27```
/resources/:
permalink: /{slug}/
template: resources
filter: tag:-news
order: featured desc, published_at desc
data:
post: page.SLUG
The error is not catched/logged properly. Needs investigation why the error is happening.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
Further problems I see:
data: page.{slug}does not provide authors,tags by default, which "breaks" the tags helper (empty output)The areas need some love and time.