Hey. I’d like to output the content of all posts in one collection on a collection page. a bit like here BBC World Service - Global News Podcast, Trump prepares for court hearing in New York (the output would consist of some text and an audio file)
What helper can I use for that? I’m not sure how I can output content of a post on a page that isn’t the post itself.
You can use the content
property on the post to output content:
And you can modify the output by adding special attributes as explained here:
Thanks a lot. I don’t quite get yet, how to use content
in a way that defines what post to pull in. would you mind giving me a mini-example how that would look when I actually used it for a collection site? Sorry, very new to all of this.
Sure. On an index (collection) page, you’d do something like this:
{{! Loop through each available post }}
{{#foreach posts}}
<article>
<h2>{{title}}<h2>
<div>{{content}}<div>
</article>
{{/foreach}}
I think a place where you might be getting tripped up is that the content
helper just outputs the content of a post in HTML. It doesn’t define which posts are defined in the collection. That happens automatically, depending on the context. For example, on your homepage, you’ll have your most recent posts by default. On a tag page, for example, getting started
, you’d have the posts tagged with getting started
.
If you want to build a separate collection, then you have two resources: custom routing and the get
helper.
ah yes, that makes sense to me. Thanks a lot, will give it a try when I get around. It’s quite impressive how easy ghost is to customize while being quite simple on the “outside”/gui view.