Use: {{#is "index"}}{{/is}}
to detect this context.
index
is the name for the main post list in your Ghost site, 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 site, or the page
context when on subsequent pages.
/
and also on subsequent pages of the post list, which live at /page/:num/
. All routes are customisable with dynamic routing.
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.
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.
index
context provides templates with access to an array of post objects and a pagination object. As with all contexts, all of the @site
global data is also available.
The number of posts provided will depend on the post per page
setting which you can configure in your package.json file. The 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.
{{#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.
home
is a special context which refers to page 1 of the index. If home
is set, index
is always set as well. home
can be used to detect that this is specifically the first page of the site and not one of the subsequent pages.
Use: {{#is "home"}}{{/is}}
to detect this context.
/
.
index.hbs
. You can optionally add a home.hbs
template to your theme which will be used instead.
posts_per_page
setting in the package.json
file.