Channel data in templates

Hi.
In your tutorial Creating content hubs with Ghost, you’re showing an example with two routes using the same template file for two different channels:

routes:
  /reviews/mobile/:
    controller: channel
    filter: tag:review+tag:mobile
    template: reviews
  /reviews/photography/:
    controller: channel
    filter: tag:review+tag:camera
    template: reviews

How would you go about displaying a channel title, let’s say “Photography”, using that template? You have to do it somehow because you’re using the same template for two different channels.
There is no mention in your documentation that there is a channel data object with some properties to use.
Furthermore, how to get a page title using that template? I’m getting a pagination page as a title, “Page 1”, which is not something you’d like to see.

Cheers.

You would do this with the data property

So for example if you made a channel like

routes:
  /photography/:
    controller: channel
    filter: tag:photography
    template: reviews
    data: tag.photography

The template would then pull {{title}} (and other meta data) from the “Photography” tag.

Thank you for this, it’s a good idea, but I think it doesn’t solve the broader issue. It would work only if channel = tag. The whole point of having a channel is that you can mix tags, or create a content hub, as it is called. So, correct me if I’m wrong here, if I have a mix of tags within a channel, data: tag.photography wouldn’t work.

Thank you for your time and effort though.

Cheers.

Sure! That’s totally fair, in that case you could potentially create a page to hold all the data you want to use for the channel - and then use data: page.photography-meta to load it in :slight_smile:

Thank you John. What would then I will be using for template property for this channel in routes.yaml? Page slug? Or the same template that I will be using for the page?

data: page.photography-meta
Pulls in the content of a page with a slug of photography-meta and assigns it to the channel

template: photography
Assigns photography.hbs as the theme file to display data, as well as the filtered list of posts.

I’m on it! Thank you so much John.

Sorry, John but no luck.
I have a page named photography-meta with slug photography and a custom route /topic/photography/ in the routes.yaml file as my channel with controller, filters, template and data properties.

  • If I go to the page URL (/photography/) then I get page meta inside the template but no posts, which is cool since there is no channel at this URL.
  • If I go to custom route URL (/topic/photography/), then I get 404.

Sorry to trouble you but as a Ghost newbie, I’m at loss here.