{"_id":"5937b23b8e8d9b002f1df2ab","category":{"_id":"5937b2388e8d9b002f1df270","version":"5937b2378e8d9b002f1df26e","project":"542fe92a5eceb608003fddc8","__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,"user":"542c5cfcddd3190e00228849","project":"542fe92a5eceb608003fddc8","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":["57a0f99a9121d42b003aa015"],"next":{"pages":[],"description":""},"createdAt":"2015-05-13T20:17:31.304Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":13,"body":"Use: `{{#is \"tag\"}}{{/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    \"0-0\": \"tag\",\n    \"0-1\": \"/tag/:slug/\",\n    \"0-2\": \"tag-:slug.hbs, tag.hbs, index.hbs\",\n    \"0-3\": \"[{post}], {pagination}, {tag}\",\n    \"0-4\": \".tag-template, .tag-:slug\",\n    \"1-0\": \"tag, [paged](doc:paged-context)\",\n    \"1-1\": \"/tag/:slug/page/2/\",\n    \"1-2\": \"tag-:slug.hbs, tag.hbs or index.hbs\",\n    \"1-3\": \"[{post}], {pagination}, {tag}\",\n    \"1-4\": \".tag-template, .tag-:slug, .paged\"\n  },\n  \"cols\": 5,\n  \"rows\": 2\n}\n[/block]\n## Description\n\nTags in Ghost each get their own page which lists out the associated posts. You are in the `tag` context when viewing the page thats lists all posts with that tag, as well as subsequent pages of posts. The `tag` context is not set on posts or pages with tags, only on the list of posts for that tag.\n\n## Routes\n\nThe default URL for tag pages is `/tag/:slug/`. The `tag` context is also set on subsequent pages of the post list, which live at `/tag/:slug/page/:num/`. The `slug` part of the URL is based on the name of the tag and can be configured in the tag admin, no other part of the URL can be configured at present.\n\n## Templates\n\nThe default template for a tag page is `index.hbs`. \n\nYou can optionally include a `tag.hbs` file in your theme which will be used for tag pages instead. \n\nAdditionally, you can provide a custom template for a specific tag. If there is a `tag-:slug.hbs` file with the `:slug` matching the tag's slug this will be used instead. \n\nFor example, if you have a tag 'photo' with the url `/tag/photo/`, adding a template called `tag-photo.hbs` will cause that template to be used for the photo tag instead of `tag.hbs`, or `index.hbs`.\n\nThese templates exist in a hierarchy. Ghost looks for a template which matches the slug (`tag-:slug.hbs`) first, then looks for `tag.hbs` and finally uses `index.hbs` if neither is available.\n\n## Data\n\nWhen in the `tag` context, a template gets access to 3 objects: the [tag object](/docs/author-context#tag-object-attributes) which matches the route, an array of [post objects](/docs/post-context#post-object-attributes) and a [pagination object](/docs/pagination#pagination-attributes). As with all contexts, all of the `:::at:::blog` global data is also available. \n\n### Tag object\n\nWhen outputting the tag attributes, you can use a block expression (`{{#tag}}{{/tag}}`) to drop into the tag scope and access all of the attributes. \n\n#### Tag object attributes\n\n- **id** - the incremental ID of the tag  \n- **name** - the name of the tag\n- **description** - a description of the tag\n- **image** - the cover image associated with the tag  ([image helper](doc:image))\n- **meta_title** - custom meta title for the page ([meta_title helper](doc:meta_title))\n- **meta_description** - Custom meta description for the page ([meta_description helper](doc:meta_description) )\n-**url** - the web address for the tag's page ([url helper](doc:url))\n\n### Post list\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\n### Pagination\n\nThe [pagination object](/docs/pagination#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\nThe `{{#tag}}{{/tag}}` block expression is useful for accessing all of the author attributes. Once inside the tag you can access the attributes and use helpers like [{{image}}](doc:image) and [{{url}}](doc:url) to output the tag's details.\n\nUsing `{{#foreach 'posts'}}{{/foreach}}` is the best way to loop through the list of posts and output each one. \n\nIf your theme does have a `tag.hbs` and `author.hbs` file all outputting similar post lists to `index.hbs` 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\": \"<!-- Everything inside of #tag pulls data from the tag -->\\n{{#tag}}\\n  <header>\\n  \\t{{#if image}}\\n    \\t<img src=\\\"{{image}}\\\" alt=\\\"{{name}}\\\" />\\n    {{/if}}\\n  </header>\\n\\n  <section class=\\\"author-profile\\\">   \\n  \\t<h1>{{name}}</h1>\\n    {{#if description}}\\n      <h2>{{description}}</h2>\\n    {{/if}}\\n  </section>\\n{{/tag}}\\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\": \"tag.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\": \"text\",\n      \"name\": \"partials/loops.hbs\"\n    }\n  ]\n}\n[/block]","excerpt":"The `tag` context","slug":"tag-context","type":"basic","title":"tag"}

tag

The `tag` context

Use: `{{#is "tag"}}{{/is}}` to detect this context. [block:parameters] { "data": { "h-0": "Context", "h-1": "Url", "h-2": "Template", "h-3": "Data", "h-4": "Body Classes", "0-0": "tag", "0-1": "/tag/:slug/", "0-2": "tag-:slug.hbs, tag.hbs, index.hbs", "0-3": "[{post}], {pagination}, {tag}", "0-4": ".tag-template, .tag-:slug", "1-0": "tag, [paged](doc:paged-context)", "1-1": "/tag/:slug/page/2/", "1-2": "tag-:slug.hbs, tag.hbs or index.hbs", "1-3": "[{post}], {pagination}, {tag}", "1-4": ".tag-template, .tag-:slug, .paged" }, "cols": 5, "rows": 2 } [/block] ## Description Tags in Ghost each get their own page which lists out the associated posts. You are in the `tag` context when viewing the page thats lists all posts with that tag, as well as subsequent pages of posts. The `tag` context is not set on posts or pages with tags, only on the list of posts for that tag. ## Routes The default URL for tag pages is `/tag/:slug/`. The `tag` context is also set on subsequent pages of the post list, which live at `/tag/:slug/page/:num/`. The `slug` part of the URL is based on the name of the tag and can be configured in the tag admin, no other part of the URL can be configured at present. ## Templates The default template for a tag page is `index.hbs`. You can optionally include a `tag.hbs` file in your theme which will be used for tag pages instead. Additionally, you can provide a custom template for a specific tag. If there is a `tag-:slug.hbs` file with the `:slug` matching the tag's slug this will be used instead. For example, if you have a tag 'photo' with the url `/tag/photo/`, adding a template called `tag-photo.hbs` will cause that template to be used for the photo tag instead of `tag.hbs`, or `index.hbs`. These templates exist in a hierarchy. Ghost looks for a template which matches the slug (`tag-:slug.hbs`) first, then looks for `tag.hbs` and finally uses `index.hbs` if neither is available. ## Data When in the `tag` context, a template gets access to 3 objects: the [tag object](/docs/author-context#tag-object-attributes) which matches the route, an array of [post objects](/docs/post-context#post-object-attributes) and a [pagination object](/docs/pagination#pagination-attributes). As with all contexts, all of the [email protected]` global data is also available. ### Tag object When outputting the tag attributes, you can use a block expression (`{{#tag}}{{/tag}}`) to drop into the tag scope and access all of the attributes. #### Tag object attributes - **id** - the incremental ID of the tag - **name** - the name of the tag - **description** - a description of the tag - **image** - the cover image associated with the tag ([image helper](doc:image)) - **meta_title** - custom meta title for the page ([meta_title helper](doc:meta_title)) - **meta_description** - Custom meta description for the page ([meta_description helper](doc:meta_description) ) -**url** - the web address for the tag's page ([url helper](doc:url)) ### Post list 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). ### Pagination The [pagination object](/docs/pagination#pagination-attributes) provided is the same everywhere. The best way to output pagination is to use the [pagination](doc:pagination) helper. ## Helpers The `{{#tag}}{{/tag}}` block expression is useful for accessing all of the author attributes. Once inside the tag you can access the attributes and use helpers like [{{image}}](doc:image) and [{{url}}](doc:url) to output the tag's details. Using `{{#foreach 'posts'}}{{/foreach}}` is the best way to loop through the list of posts and output each one. If your theme does have a `tag.hbs` and `author.hbs` file all outputting similar post lists to `index.hbs` 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": "<!-- Everything inside of #tag pulls data from the tag -->\n{{#tag}}\n <header>\n \t{{#if image}}\n \t<img src=\"{{image}}\" alt=\"{{name}}\" />\n {{/if}}\n </header>\n\n <section class=\"author-profile\"> \n \t<h1>{{name}}</h1>\n {{#if description}}\n <h2>{{description}}</h2>\n {{/if}}\n </section>\n{{/tag}}\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": "tag.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": "text", "name": "partials/loops.hbs" } ] } [/block]