I’ve just started developing a theme and have run into a problem that has been raised before.
What version of Ghost are you using? 2.3
I have created a page with title Page1 and has slug page1, and is accessible from /page1/.
I have also created a page with title ChildPage1 and has slug child-page1 and is accessible from /page1/child-page1/
Everything else works as expected.
The problem is that {{meta_title}} and {{body_class}} are empty. How can I make this work?
The routes yaml contains this:
/page1/:
data: page.page1
redirect: false
template:
- custom-page1
…
This is the referenced issue in Github.
opened 12:46PM - 29 Oct 18 UTC
closed 06:18AM - 21 Aug 19 UTC
bug
server / core
affects:api
later
affects:routing
Reported in the forum: https://forum.ghost.org/t/when-using-dynamic-routes-meta-… title-and-body-class-are-empty/3765
## Custom Meta Title
```
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:
1. the StaticRoutesRouter does not forward the correct context, [see](https://github.com/TryGhost/Ghost/blob/2.3.0/core/server/services/routing/StaticRoutesRouter.js#L85). It has to forward the resource type as well (e.g. `page`) if the `data` key was provided.
2. The meta [title helper](https://github.com/TryGhost/Ghost/blob/2.3.0/core/server/data/meta/title.js#L37) is not aware of the `this.page` context object -> `data.page`.
## Body Class Helper
```
{{body_class}}
```
This [helper](https://github.com/TryGhost/Ghost/blob/2.3.0/core/server/helpers/body_class.js#L15) 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);
## Workaround
```
{{#page}}
{{meta_title}}
{{/page}}
```
Ghost: master
The version of Ghost I’m running is 2.6.1.
This is my routes.yaml
file.
routes:
/: home
/about/:
data:
page: page.about
template:
- about
collections:
/news/:
permalink: /news/{slug}/
data:
page: page.news
template:
- news
taxonomies:
tag: /tag/{slug}/
author: /author/{slug}/
In the admin I have static pages set up with slugs about
and news
. I would like to use these to manage things like the page title, meta title, meta description, social card information, etc. However as the previous topic suggests the page data is not coming through in context. The {{meta_title}}
for the /about/
route is the blog title, and for the /news/
collection it’s the blog title with the pagination information appended, e.g. (Page 1)
. Strangely though the {{meta_description}}
property is being populated in the template correctly.
That’s the first query/issue.
The second is that the {{current}}
helper in the {{navigation}}
. I have /news/
as one of my navigation items which for the listing page correctly adds the nav-current
class, however for the nested posts /news/{slug}/
it is not set. Is it possible to do this?
Thanks in advance!
1 Like
I have the same issue.
can not change title when use custom collections
/product/:
permalink: /product/{slug}/
filter: tag:[product]
data: page.tmp-product
the web title show “site-name Page1"
system
Closed
December 18, 2018, 2:00am
3
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.