{"category":{"version":"58c81e8e693cdd1900606acf","project":"542fe92a5eceb608003fddc8","_id":"58c81e8e693cdd1900606ad1","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-05-13T19:08:44.260Z","from_sync":false,"order":1,"slug":"context-reference","title":"Context Reference"},"parentDoc":null,"project":"542fe92a5eceb608003fddc8","user":"542c5cfcddd3190e00228849","version":{"__v":1,"_id":"58c81e8e693cdd1900606acf","project":"542fe92a5eceb608003fddc8","createdAt":"2017-03-14T16:47:10.620Z","releaseDate":"2017-03-14T16:47:10.620Z","categories":["58c81e8e693cdd1900606ad0","58c81e8e693cdd1900606ad1","58c81e8e693cdd1900606ad2","58c81e8e693cdd1900606ad3","58c81e8e693cdd1900606ad4","58c81e8e693cdd1900606ad5"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"0.11.7","version":"0.11.7"},"_id":"58c81e8f693cdd1900606b06","__v":0,"updates":["5783f16b5cbce30e0074e2ab"],"next":{"pages":[],"description":""},"createdAt":"2015-05-13T20:17:01.037Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":8,"body":"Use: `{{#is \"index\"}}{{/is}}` to detect this context.\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Context\",\n    \"h-1\": \"Url\",\n    \"h-2\": \"Template\",\n    \"h-3\": \"Data\",\n    \"h-4\": \"Body Classes\",\n    \"1-0\": \"index, [paged](doc:paged-context)\",\n    \"1-1\": \"/page/2/\",\n    \"1-2\": \"index.hbs\",\n    \"1-3\": \"[{post}], {pagination}\",\n    \"1-4\": \".paged\",\n    \"0-0\": \"index, [home](doc:home-context)\",\n    \"0-1\": \"/\",\n    \"0-2\": \"home.hbs, index.hbs\",\n    \"0-3\": \"[{post}], {pagination}\",\n    \"0-4\": \".home-template\"\n  },\n  \"cols\": 5,\n  \"rows\": 2\n}\n[/block]\n## Description\n\n`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.\n\n## Routes\n\nThe 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.\n\n## Templates\n\nThe 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](doc:home-context) documentation for more details.\n\nNote 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.\n\n## Data\n\nThe `index` context provides templates with access to an array of [post objects](/docs/post-context#section-post-object-attributes) and a [pagination object](/docs/pagination#section-pagination-attributes). As with all contexts, all of the `:::at:::blog` global data is also available. \n\nThe 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.\n\nEach of the posts can be looped through using [`{{#foreach 'posts'}}{{/foreach}}`](doc:foreach). The template code inside the block will be rendered for each post, and have access to all of the [post object attributes](/docs/post-context#post-object-attributes).\n\nThe [pagination object](/docs/pagination#section-pagination-attributes) provided is the same everywhere. The best way to output pagination is to use the [pagination](doc:pagination) helper.\n\n## Helpers\n\nUsing `{{#foreach 'posts'}}{{/foreach}}` is the best way to loop through your posts and output each one. \n\nIf 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.\n\nThe [{{pagination}}](doc:pagination) helper is the best way to output pagination. This is fully customisable, see the [pagination helper](doc:pagination) docs for details.\n\n## Example Code\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<header>\\n  <h1 class=\\\"page-title\\\">{{@blog.title}}</h1>\\n  <h2 class=\\\"page-description\\\">{{@blog.description}}</h2>    \\n</header>\\n\\n<main role=\\\"main\\\">\\n<!-- This is the post loop - each post will be output using this markup -->\\n  {{#foreach posts}}\\n\\t<article class=\\\"{{post_class}}\\\">\\n \\t\\t<header class=\\\"post-header\\\">\\n   \\t\\t<h2><a href=\\\"{{url}}\\\">{{title}}</a></h2>\\n    </header>\\n    <section class=\\\"post-excerpt\\\">\\n \\t\\t\\t<p>{{excerpt words=\\\"26\\\"}} <a class=\\\"read-more\\\" href=\\\"{{url}}\\\">...</a></p>\\n    </section>\\n    <footer class=\\\"post-meta\\\">\\n      {{#if author.image}}<img src=\\\"{{author.image}}\\\" alt=\\\"Author image\\\" />{{/if}}\\n      {{author}}\\n      {{tags prefix=\\\" on \\\"}}\\n      <time class=\\\"post-date\\\" datetime=\\\"{{date format='YYYY-MM-DD'}}\\\">{{date format=\\\"DD MMMM YYYY\\\"}}</time>\\n    </footer>\\n  </article>\\n  {{/foreach}}\\n\\n</main>\\n\\n<!-- Previous/next page links - displayed on every page -->\\n{{pagination}}\\n\",\n      \"language\": \"html\",\n      \"name\": \"index.hbs\"\n    }\n  ]\n}\n[/block]\nUsing a partial:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<header>\\n    <h1 class=\\\"page-title\\\">{{@blog.title}}</h1>\\n    <h2 class=\\\"page-description\\\">{{@blog.description}}</h2>    \\n</header>\\n\\n<main role=\\\"main\\\">\\n  <!-- includes the post loop - partials/loop.hbs -->\\n  {{> \\\"loop\\\"}}\\n</main>\\n\\n<!-- Previous/next page links - displayed on every page -->\\n{{pagination}}\",\n      \"language\": \"html\",\n      \"name\": \"index.hbs\"\n    },\n    {\n      \"code\": \"<!-- This is the post loop - each post will be output using this markup -->\\n{{#foreach posts}}\\n<article class=\\\"{{post_class}}\\\">\\n\\t<header class=\\\"post-header\\\">\\n\\t\\t<h2><a href=\\\"{{url}}\\\">{{title}}</a></h2>\\n\\t</header>\\n\\t<section class=\\\"post-excerpt\\\">\\n\\t\\t<p>{{excerpt words=\\\"26\\\"}} <a class=\\\"read-more\\\" href=\\\"{{url}}\\\">...</a></p>\\n\\t</section>\\n\\t<footer class=\\\"post-meta\\\">\\n\\t\\t{{#if author.image}}<img src=\\\"{{author.image}}\\\" alt=\\\"Author image\\\" />{{/if}}\\n\\t\\t{{author}}\\n\\t\\t{{tags prefix=\\\" on \\\"}}\\n\\t\\t<time class=\\\"post-date\\\" datetime=\\\"{{date format='YYYY-MM-DD'}}\\\">{{date format=\\\"DD MMMM YYYY\\\"}}</time>\\n\\t</footer>\\n</article>\\n{{/foreach}}\",\n      \"language\": \"html\",\n      \"name\": \"partials/loop.hbs\"\n    }\n  ]\n}\n[/block]","excerpt":"The `index` context","slug":"index-context","type":"basic","title":"index"}

index

The `index` context

Use: `{{#is "index"}}{{/is}}` to detect this context. [block:parameters] { "data": { "h-0": "Context", "h-1": "Url", "h-2": "Template", "h-3": "Data", "h-4": "Body Classes", "1-0": "index, [paged](doc:paged-context)", "1-1": "/page/2/", "1-2": "index.hbs", "1-3": "[{post}], {pagination}", "1-4": ".paged", "0-0": "index, [home](doc:home-context)", "0-1": "/", "0-2": "home.hbs, index.hbs", "0-3": "[{post}], {pagination}", "0-4": ".home-template" }, "cols": 5, "rows": 2 } [/block] ## 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](doc: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](/docs/post-context#section-post-object-attributes) and a [pagination object](/docs/pagination#section-pagination-attributes). 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}}`](doc:foreach). The template code inside the block will be rendered for each post, and have access to all of the [post object attributes](/docs/post-context#post-object-attributes). The [pagination object](/docs/pagination#section-pagination-attributes) provided is the same everywhere. The best way to output pagination is to use the [pagination](doc: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}}](doc:pagination) helper is the best way to output pagination. This is fully customisable, see the [pagination helper](doc:pagination) docs for details. ## Example Code [block:code] { "codes": [ { "code": "<header>\n <h1 class=\"page-title\">{{@blog.title}}</h1>\n <h2 class=\"page-description\">{{@blog.description}}</h2> \n</header>\n\n<main role=\"main\">\n<!-- This is the post loop - each post will be output using this markup -->\n {{#foreach posts}}\n\t<article class=\"{{post_class}}\">\n \t\t<header class=\"post-header\">\n \t\t<h2><a href=\"{{url}}\">{{title}}</a></h2>\n </header>\n <section class=\"post-excerpt\">\n \t\t\t<p>{{excerpt words=\"26\"}} <a class=\"read-more\" href=\"{{url}}\">...</a></p>\n </section>\n <footer class=\"post-meta\">\n {{#if author.image}}<img src=\"{{author.image}}\" alt=\"Author image\" />{{/if}}\n {{author}}\n {{tags prefix=\" on \"}}\n <time class=\"post-date\" datetime=\"{{date format='YYYY-MM-DD'}}\">{{date format=\"DD MMMM YYYY\"}}</time>\n </footer>\n </article>\n {{/foreach}}\n\n</main>\n\n<!-- Previous/next page links - displayed on every page -->\n{{pagination}}\n", "language": "html", "name": "index.hbs" } ] } [/block] Using a partial: [block:code] { "codes": [ { "code": "<header>\n <h1 class=\"page-title\">{{@blog.title}}</h1>\n <h2 class=\"page-description\">{{@blog.description}}</h2> \n</header>\n\n<main role=\"main\">\n <!-- includes the post loop - partials/loop.hbs -->\n {{> \"loop\"}}\n</main>\n\n<!-- Previous/next page links - displayed on every page -->\n{{pagination}}", "language": "html", "name": "index.hbs" }, { "code": "<!-- This is the post loop - each post will be output using this markup -->\n{{#foreach posts}}\n<article class=\"{{post_class}}\">\n\t<header class=\"post-header\">\n\t\t<h2><a href=\"{{url}}\">{{title}}</a></h2>\n\t</header>\n\t<section class=\"post-excerpt\">\n\t\t<p>{{excerpt words=\"26\"}} <a class=\"read-more\" href=\"{{url}}\">...</a></p>\n\t</section>\n\t<footer class=\"post-meta\">\n\t\t{{#if author.image}}<img src=\"{{author.image}}\" alt=\"Author image\" />{{/if}}\n\t\t{{author}}\n\t\t{{tags prefix=\" on \"}}\n\t\t<time class=\"post-date\" datetime=\"{{date format='YYYY-MM-DD'}}\">{{date format=\"DD MMMM YYYY\"}}</time>\n\t</footer>\n</article>\n{{/foreach}}", "language": "html", "name": "partials/loop.hbs" } ] } [/block]