# Dynamic routing - page/post data context in default.hbs + nested navigation on custom collections

**URL:** <https://forum.ghost.org/t/dynamic-routing-page-post-data-context-in-default-hbs-nested-navigation-on-custom-collections/4204>\
**Category:** Developer help\
**Created:** [November 21, 2018, 5:32pm UTC](https://forum.ghost.org/t/dynamic-routing-page-post-data-context-in-default-hbs-nested-navigation-on-custom-collections/4204 "2018-11-21T17:32:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomblakemore](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/tomblakemore/32/1963_2.png) [@tomblakemore](https://forum.ghost.org/u/tomblakemore)\
**Post date:** [November 21, 2018, 5:32pm UTC](https://forum.ghost.org/t/dynamic-routing-page-post-data-context-in-default-hbs-nested-navigation-on-custom-collections/4204/1 "2018-11-21T17:32:32Z")

</div>

I’ve just started developing a theme and have run into a problem that has been raised before.

> [@When using dynamic routes {{meta\_title}} and {{body\_class}} are empty](https://forum.ghost.org/t/when-using-dynamic-routes-meta-title-and-body-class-are-empty/3765):
>
> 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.

> <https://github.com/TryGhost/Ghost/issues/10082>
>
> 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.

```auto
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!

---

<div class="post-metadata">

**Author:** ![DaZiYuan](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/daziyuan/32/1990_2.png) [@DaZiYuan](https://forum.ghost.org/u/DaZiYuan)\
**Post date:** [December 4, 2018, 1:59am UTC](https://forum.ghost.org/t/dynamic-routing-page-post-data-context-in-default-hbs-nested-navigation-on-custom-collections/4204/2 "2018-12-04T01:59:58Z")

</div>

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"

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/ghost2/original/2X/b/ba9ce5100b8bb264586f4f572545596b2ce3f081.png) [@system](https://forum.ghost.org/u/system)\
**Post date:** [December 18, 2018, 2:00am UTC](https://forum.ghost.org/t/dynamic-routing-page-post-data-context-in-default-hbs-nested-navigation-on-custom-collections/4204/3 "2018-12-18T02:00:04Z")

</div>

Closed on December 18, 2018, 2:00am UTC

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