{"_id":"5937b2388e8d9b002f1df299","category":{"_id":"5937b2388e8d9b002f1df272","version":"5937b2378e8d9b002f1df26e","project":"542fe92a5eceb608003fddc8","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-10-04T12:45:40.548Z","from_sync":false,"order":3,"slug":"helper-reference","title":"Helper Reference"},"project":"542fe92a5eceb608003fddc8","user":"542c5cfcddd3190e00228849","parentDoc":null,"version":{"_id":"5937b2378e8d9b002f1df26e","project":"542fe92a5eceb608003fddc8","__v":1,"createdAt":"2017-06-07T07:58:47.936Z","releaseDate":"2017-06-07T07:58:47.936Z","categories":["5937b2388e8d9b002f1df26f","5937b2388e8d9b002f1df270","5937b2388e8d9b002f1df271","5937b2388e8d9b002f1df272","5937b2388e8d9b002f1df273","5937b2388e8d9b002f1df274"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0.0"},"__v":0,"updates":["552fbe060c01e717000f6536"],"next":{"pages":[],"description":""},"createdAt":"2015-04-07T16:03:39.708Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":49,"body":"[block:html]\n{\n  \"html\": \"<div class=\\\"github-deeplinks\\\">\\n    <a href=\\\"https://github.com/TryGhost/Ghost/blob/master/core/server/helpers/prev_next.js\\\"><i class=\\\"fa fa-github-alt fa-right\\\"></i>Source</a>\\n    <a href=\\\"https://github.com/TryGhost/Ghost/blob/master/core/test/unit/server_helpers/prev_next_spec.js\\\" class=\\\"fa fa-check-square-o fa-right\\\">Tests</a>\\n</div>\"\n}\n[/block]\nUsage: `{{#prev_post}}{{title}}{{/prev_post}}` -  `{{#next_post}}{{title}}{{/next_post}}`\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"[Block](/docs/helpers#section-block), [Ghost](/docs/helpers#section-ghost), [Query](/docs/helpers#section-query)\",\n    \"h-0\": \"Types\",\n    \"h-1\": \"Parameters\",\n    \"h-2\": \"Attributes\",\n    \"0-1\": \"n/a\",\n    \"0-2\": \"n/a\"\n  },\n  \"cols\": 3,\n  \"rows\": 1\n}\n[/block]\n### Description\n\nWhen in the scope of a post, you can call the next or previous post helper, which performs a query against the API to fetch the next or previous post in accordance with the chronological order of the blog.\n\nInside of the opening and closing tags of the `{{#next_post}}{{/next_post}}` or `{{#prev_post}}{{/prev-post}}` helper, the normal helpers for [outputting posts](/docs/post) will work, but will output the details of the post that was fetched from the API, rather than the original post. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{{#post}}\\n\\t<h2>{{title}}</h2>\\n\\t<div class=\\\"{{post_class}}\\\">\\n\\t\\t{{content}}\\n\\t</div>\\n\\n\\t{{#prev_post}}\\n\\t\\t<a href=\\\"{{url}}\\\">{{title}}</a>\\n\\t{{/prev_post}}\\n\\n\\t{{#next_post}}\\n\\t\\t<a href=\\\"{{url}}\\\">{{title}}</a>\\n\\t{{/next_post}}\\n{{/post}}\",\n      \"language\": \"html\",\n      \"name\": \"Handlebars\"\n    }\n  ]\n}\n[/block]\nLike all block helpers, `next_post` and `prev_post` support adding an `{{else}}` block or using `^` instead of `#` for negation - this means that the `{{#next_post}}` and `{{else}}` blocks are reversed if you use `{{^next_post}}` and `{{else}}` instead. This can be used to output content if there is no next or previous post available. \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{{#next_post}}\\n\\t<p><a href=\\\"{{url}}\\\">{{title}}</a></p>\\n{{else}}\\n\\t<p>No more posts!</p>\\n{{/next_post}}\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\n**Note:** The next and previous post helpers *cannot* be nested inside each other. This is because they are performing a query, and we currently cannot support nesting queries inside each other. \n\nYou *can* do more than one query on a page though, so you can use both `{{#next_post}}` and `{{#prev_post}}` in the same template, or call either of them multiple times.","excerpt":"`{{prev_post}}` & `{{next_post}}` Helpers - Fetch the next or previous post from the current post","slug":"prev_next_post","type":"basic","title":"prev_post & next_post"}

prev_post & next_post

`{{prev_post}}` & `{{next_post}}` Helpers - Fetch the next or previous post from the current post

[block:html] { "html": "<div class=\"github-deeplinks\">\n <a href=\"https://github.com/TryGhost/Ghost/blob/master/core/server/helpers/prev_next.js\"><i class=\"fa fa-github-alt fa-right\"></i>Source</a>\n <a href=\"https://github.com/TryGhost/Ghost/blob/master/core/test/unit/server_helpers/prev_next_spec.js\" class=\"fa fa-check-square-o fa-right\">Tests</a>\n</div>" } [/block] Usage: `{{#prev_post}}{{title}}{{/prev_post}}` - `{{#next_post}}{{title}}{{/next_post}}` [block:parameters] { "data": { "0-0": "[Block](/docs/helpers#section-block), [Ghost](/docs/helpers#section-ghost), [Query](/docs/helpers#section-query)", "h-0": "Types", "h-1": "Parameters", "h-2": "Attributes", "0-1": "n/a", "0-2": "n/a" }, "cols": 3, "rows": 1 } [/block] ### Description When in the scope of a post, you can call the next or previous post helper, which performs a query against the API to fetch the next or previous post in accordance with the chronological order of the blog. Inside of the opening and closing tags of the `{{#next_post}}{{/next_post}}` or `{{#prev_post}}{{/prev-post}}` helper, the normal helpers for [outputting posts](/docs/post) will work, but will output the details of the post that was fetched from the API, rather than the original post. [block:code] { "codes": [ { "code": "{{#post}}\n\t<h2>{{title}}</h2>\n\t<div class=\"{{post_class}}\">\n\t\t{{content}}\n\t</div>\n\n\t{{#prev_post}}\n\t\t<a href=\"{{url}}\">{{title}}</a>\n\t{{/prev_post}}\n\n\t{{#next_post}}\n\t\t<a href=\"{{url}}\">{{title}}</a>\n\t{{/next_post}}\n{{/post}}", "language": "html", "name": "Handlebars" } ] } [/block] Like all block helpers, `next_post` and `prev_post` support adding an `{{else}}` block or using `^` instead of `#` for negation - this means that the `{{#next_post}}` and `{{else}}` blocks are reversed if you use `{{^next_post}}` and `{{else}}` instead. This can be used to output content if there is no next or previous post available. [block:code] { "codes": [ { "code": "{{#next_post}}\n\t<p><a href=\"{{url}}\">{{title}}</a></p>\n{{else}}\n\t<p>No more posts!</p>\n{{/next_post}}", "language": "html" } ] } [/block] **Note:** The next and previous post helpers *cannot* be nested inside each other. This is because they are performing a query, and we currently cannot support nesting queries inside each other. You *can* do more than one query on a page though, so you can use both `{{#next_post}}` and `{{#prev_post}}` in the same template, or call either of them multiple times.