Theme development: can I have multiple data sources in one template?

Hi, I’m just getting my feet wet with handlebars and ghost theme development.

I’ve just read through the Routing section of the docs to get an idea for different ways to populate a page with data, but I have a problem: I would like to create a front page that sources its content from multiple channels instead of just one. I may have overlooked this but I’m not sure this is even possible?

To illustrate, what I’m trying to achieve is the following:

  • A collage of article thumbnails (let’s say “featured”, posts, but maybe just based on a hidden tag instead)
  • Below, some photo posts (identified / filtered by a hidden tag)
  • Below, the X most recent posts (blog-style, i.e. just all posts filtered by descending date)

Is this possible with handlebars/ghost? I assume this should be a job for channels (?) but I have not seen multiple channels being used in a single template file or routing definition, so I’m not sure how to implement this. If this will not work, what are possible workarounds to achieve a page composition like this?
I have a background in WordPress development (which I’d like to leave behind), in that case I’d have multiple get_posts(...) calls with different filter criteria set to grab those lists of posts…

Yes! This would be a job for the {{#get}} helper (which is named after get_posts() )

Channels and routes are for when you want to build custom streams of content with pagination, for example how DESK magazine structures different Series:

1 Like

Thanks John, awesome! That is exactly what I meant.

This brings me to my next, tangential question: When I’m looping over a context, or in a {{#get}} for that matter, is {{#foreach}} the only way to loop over the posts, or is there a way to grab the “next” post from the iterator?

My use case is the aforementioned collage of featured articles, which looks like this in HTML:

It would be much easier to{{#get}} 5 featured posts and then manually pulling their data in the right area, rather than looping over them end doing weird DOM writing with {{#has number="1"}} switch cases. That does seem to be possible though, so if {{#foreach}} is the only way to look, I can make do with it.