The Ghost Themes Developer Hub

Welcome to the Ghost Themes developer hub. You'll find comprehensive guides and documentation to help you start working with Ghost Themes as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

index

The index context

Use: {{#is "index"}}{{/is}} to detect this context.

Context
Url
Template
Data
Body Classes

index, home

/

home.hbs, index.hbs

[{post}], {pagination}

.home-template

index, paged

/page/2/

index.hbs

[{post}], {pagination}

.paged

Description

index is the name for the main post list in your Ghost blog, the index context includes the home page and subsequent pages of the main post list. The index context is always paired with either the home context when on the first page of your blog, or the paged context when on subsequent pages.

Routes

The index context is present on both the root URL of the blog, e.g. / and also on subsequent pages of the post list, which live at /page/:num/. These routes are not customisable at present.

Templates

The index context is rendered with index.hbs by default. This template is required in all Ghost themes. If there is a home.hbs present in the theme, the home page will be rendered using that instead - see the home context documentation for more details.

Note that the index.hbs template is also used to output the tag and author contexts, if no specific tag.hbs or author.hbs templates are provided.

Data

The index context provides templates with access to an array of post objects and a pagination object. As with all contexts, all of the @blog global data is also available.

The number of posts provided will depend on the post per page setting which is configured in the Ghost admin (the default is 6). The provided array will provide the correct posts for the current page number, with the posts ordered chronologically, newest first. Therefore on the home page, the theme will have access to the first 6 posts by default. On /page/2/ the theme will have access to posts 7-12.

Each of the posts can be looped through using {{#foreach 'posts'}}{{/foreach}}. The template code inside the block will be rendered for each post, and have access to all of the post object attributes.

The pagination object provided is the same everywhere. The best way to output pagination is to use the pagination helper.

Helpers

Using {{#foreach 'posts'}}{{/foreach}} is the best way to loop through your posts and output each one.

If your theme does have a tag.hbs and author.hbs file all outputting similar post lists you may wish to use a partial to define your post list item, e.g. {{> "loop"}}. There's an example showing this in detail below.

The {{pagination}} helper is the best way to output pagination. This is fully customisable, see the pagination helper docs for details.

Example Code

<header>
  <h1 class="page-title">{{@blog.title}}</h1>
  <h2 class="page-description">{{@blog.description}}</h2>    
</header>

<main role="main">
<!-- This is the post loop - each post will be output using this markup -->
  {{#foreach posts}}
	<article class="{{post_class}}">
 		<header class="post-header">
   		<h2><a href="{{url}}">{{title}}</a></h2>
    </header>
    <section class="post-excerpt">
 			<p>{{excerpt words="26"}} <a class="read-more" href="{{url}}">...</a></p>
    </section>
    <footer class="post-meta">
      {{#if author.profile_image}}<img src="{{author.profile_image}}" alt="Author image" />{{/if}}
      {{author}}
      {{tags prefix=" on "}}
      <time class="post-date" datetime="{{date format='YYYY-MM-DD'}}">{{date format="DD MMMM YYYY"}}</time>
    </footer>
  </article>
  {{/foreach}}

</main>

<!-- Previous/next page links - displayed on every page -->
{{pagination}}

Using a partial:

<header>
    <h1 class="page-title">{{@blog.title}}</h1>
    <h2 class="page-description">{{@blog.description}}</h2>    
</header>

<main role="main">
  <!-- includes the post loop - partials/loop.hbs -->
  {{> "loop"}}
</main>

<!-- Previous/next page links - displayed on every page -->
{{pagination}}
<!-- This is the post loop - each post will be output using this markup -->
{{#foreach posts}}
<article class="{{post_class}}">
	<header class="post-header">
		<h2><a href="{{url}}">{{title}}</a></h2>
	</header>
	<section class="post-excerpt">
		<p>{{excerpt words="26"}} <a class="read-more" href="{{url}}">...</a></p>
	</section>
	<footer class="post-meta">
		{{#if author.profile_image}}<img src="{{author.profile_image}}" alt="Author image" />{{/if}}
		{{author}}
		{{tags prefix=" on "}}
		<time class="post-date" datetime="{{date format='YYYY-MM-DD'}}">{{date format="DD MMMM YYYY"}}</time>
	</footer>
</article>
{{/foreach}}

index

The index context