{"_id":"5937b23b8e8d9b002f1df2a6","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"},"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":[],"next":{"pages":[],"description":""},"createdAt":"2015-05-13T19:10:45.600Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":8,"body":"Each page in a Ghost theme belongs to a context. The context can be determined by the URL, and tells you which template will be used, what data will be available to output and what will be output by the [`{{body_class}}`](doc:body_class) helper. \n\n## What is a context?\n\nEach Ghost blog follows a structure: certain URLs, or 'routes' map to views which are intended to display specific data - a list of posts, a single post or an RSS feed. The route determines what data is meant to be shown and what template file gets used to render it. \n\nFor example, the page which contains the default first post when you start a Ghost blog lives under the URL `/welcome-to-ghost/` and is intended show the content of this post. Ghost will output this page by providing the `post.hbs` template with all the data for the given post, as well as some global data. This is referred to as the `post` context - whenever you're viewing a single post via its own URL, you are in the `post` context.\n\nWhenever you activate a context by visiting a URL, you are guaranteed that you will have access to a particular set of data for that context, and that the page will be rendered using a particular template. Ghost does not provide access to all data in all contexts, instead it optimises the fetching of the data and rendering of the page so that the blog is super fast. \n\n## Using contexts in themes\n\nThe context is what drives a whole bunch of how themes work. As well as determining what data is available and which template is used to render the page, the context has an impact on several helpers. \n\nThe [{{body_class}} helper](doc:body_class) outputs different classes based on the current context.\n\nThe [{{meta_title}} helper](doc:meta_title) outputs different things based on the current context and whether there is a specific `meta_title` property available. E.g. when in the `post` context, the helper knows it can use `post.meta_title`, and in a `tag` context it knows it can use `tag.meta_title`.\n\nIf you'd like to detect the current context, for example in a partial template that is shared between many contexts, you can do so using the [{{#is}} helper](doc:is). Pass it a context and it will execute the contained block only when in that context.\n\n## Context Table\n\nThe table below provides the details of all the different contexts available in Ghost. It shows what the name of the context is, what their URLs or routes will look like, which template they use (in order of precedence), what data they have available to them and what will be output by the [`{{body_class}}`](doc:body_class) helper.\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\": \"[index](doc:index-context), [home](doc:home-context)\",\n    \"0-1\": \"/\",\n    \"0-2\": \"[home.hbs](/docs/templates#home-hbs), [index.hbs](/docs/templates#index-hbs)\",\n    \"0-3\": \"[{post}], {pagination}\",\n    \"0-4\": \".home-template\",\n    \"1-0\": \"[index](doc:index-context), [paged](doc:paged-context)\",\n    \"1-1\": \"/page/2/\",\n    \"1-2\": \"[index.hbs](/docs/templates#index-hbs)\",\n    \"1-3\": \"[{post}], {pagination}\",\n    \"1-4\": \".paged\",\n    \"2-0\": \"[post](doc:post-context)\",\n    \"2-1\": \"/:permalink/\",\n    \"2-2\": \"[post-:slug.hbs](/docs/templates#post-hbs), [post.hbs](/docs/templates#post-hbs)\",\n    \"2-3\": \"{post}\",\n    \"2-4\": \".post-template, .tag-:slug\",\n    \"4-0\": \"[page](doc:page-context)\",\n    \"4-1\": \"/:slug/\",\n    \"4-2\": \"[page-:slug.hbs](/docs/templates#page-hbs), [page.hbs](/docs/templates#page-hbs), [post.hbs](/docs/templates#post-hbs)\",\n    \"4-4\": \".page-template, .tag-:slug\",\n    \"4-3\": \"{post}\",\n    \"5-0\": \"[tag](doc:tag-context)\",\n    \"5-1\": \"/tag/:slug/\",\n    \"5-2\": \"[tag-:slug.hbs](/docs/templates#tags-hbs), [tag.hbs](/docs/templates#tags-hbs), [index.hbs](/docs/templates#index-hbs)\",\n    \"5-3\": \"[{post}], {pagination}, {tag}\",\n    \"5-4\": \".tag-template, .tag-:slug\",\n    \"6-0\": \"[tag](doc:tag-context), [paged](doc:paged-context)\",\n    \"6-1\": \"/tag/:slug/page/2/\",\n    \"6-2\": \"[tag-:slug.hbs](/docs/templates#tags-hbs), [tag.hbs](/docs/templates#tags-hbs) or [index.hbs](/docs/templates#index-hbs)\",\n    \"6-3\": \"[{post}], {pagination}, {tag}\",\n    \"6-4\": \".tag-template, .tag-:slug, .paged\",\n    \"7-0\": \"[author](doc:author-context)\",\n    \"7-1\": \"/author/:slug/\",\n    \"8-0\": \"[author](doc:author-context), [paged](doc:paged-context)\",\n    \"9-0\": \"[private](doc:private-context)\",\n    \"7-2\": \"[author-:slug.hbs](/docs/templates#author-hbs), [author.hbs](/docs/templates#author-hbs) or [index.hbs](/docs/templates#index-hbs)\",\n    \"7-3\": \"[{post}], {pagination}, {author}\",\n    \"8-3\": \"[{post}], {pagination}, {author}\",\n    \"7-4\": \".author-template, .author-:slug\",\n    \"8-4\": \".author-template, .author-:slug .paged\",\n    \"8-1\": \"/author/:slug/page/2/\",\n    \"8-2\": \"[author-:slug.hbs](/docs/templates#author-hbs), [author.hbs](/docs/templates#author-hbs), [index.hbs](/docs/templates#index-hbs)\",\n    \"9-3\": \"{error}\",\n    \"9-1\": \"/private/\",\n    \"9-2\": \"[private.hbs](/docs/templates#private-hbs)\",\n    \"9-4\": \".private-template\",\n    \"10-0\": \"[subscribe](doc:subscribe)\",\n    \"10-1\": \"/subscribe/\",\n    \"10-2\": \"[subscribe.hbs](/docs/templates#private-hbs)\",\n    \"10-3\": \"Documentation in progress ✨\",\n    \"3-0\": \"[amp](doc:amp-context)\",\n    \"3-1\": \"/:permalink/amp/\",\n    \"3-3\": \"{post}\",\n    \"3-2\": \"[amp.hbs](doc:amp)\",\n    \"3-4\": \".amp-template\"\n  },\n  \"cols\": 5,\n  \"rows\": 11\n}\n[/block]","excerpt":"An explanation of contexts in Ghost themes","slug":"context-overview","type":"basic","title":"Context Overview"}

Context Overview

An explanation of contexts in Ghost themes

Each page in a Ghost theme belongs to a context. The context can be determined by the URL, and tells you which template will be used, what data will be available to output and what will be output by the [`{{body_class}}`](doc:body_class) helper. ## What is a context? Each Ghost blog follows a structure: certain URLs, or 'routes' map to views which are intended to display specific data - a list of posts, a single post or an RSS feed. The route determines what data is meant to be shown and what template file gets used to render it. For example, the page which contains the default first post when you start a Ghost blog lives under the URL `/welcome-to-ghost/` and is intended show the content of this post. Ghost will output this page by providing the `post.hbs` template with all the data for the given post, as well as some global data. This is referred to as the `post` context - whenever you're viewing a single post via its own URL, you are in the `post` context. Whenever you activate a context by visiting a URL, you are guaranteed that you will have access to a particular set of data for that context, and that the page will be rendered using a particular template. Ghost does not provide access to all data in all contexts, instead it optimises the fetching of the data and rendering of the page so that the blog is super fast. ## Using contexts in themes The context is what drives a whole bunch of how themes work. As well as determining what data is available and which template is used to render the page, the context has an impact on several helpers. The [{{body_class}} helper](doc:body_class) outputs different classes based on the current context. The [{{meta_title}} helper](doc:meta_title) outputs different things based on the current context and whether there is a specific `meta_title` property available. E.g. when in the `post` context, the helper knows it can use `post.meta_title`, and in a `tag` context it knows it can use `tag.meta_title`. If you'd like to detect the current context, for example in a partial template that is shared between many contexts, you can do so using the [{{#is}} helper](doc:is). Pass it a context and it will execute the contained block only when in that context. ## Context Table The table below provides the details of all the different contexts available in Ghost. It shows what the name of the context is, what their URLs or routes will look like, which template they use (in order of precedence), what data they have available to them and what will be output by the [`{{body_class}}`](doc:body_class) helper. [block:parameters] { "data": { "h-0": "Context", "h-1": "Url", "h-2": "Template", "h-3": "Data", "h-4": "Body Classes", "0-0": "[index](doc:index-context), [home](doc:home-context)", "0-1": "/", "0-2": "[home.hbs](/docs/templates#home-hbs), [index.hbs](/docs/templates#index-hbs)", "0-3": "[{post}], {pagination}", "0-4": ".home-template", "1-0": "[index](doc:index-context), [paged](doc:paged-context)", "1-1": "/page/2/", "1-2": "[index.hbs](/docs/templates#index-hbs)", "1-3": "[{post}], {pagination}", "1-4": ".paged", "2-0": "[post](doc:post-context)", "2-1": "/:permalink/", "2-2": "[post-:slug.hbs](/docs/templates#post-hbs), [post.hbs](/docs/templates#post-hbs)", "2-3": "{post}", "2-4": ".post-template, .tag-:slug", "4-0": "[page](doc:page-context)", "4-1": "/:slug/", "4-2": "[page-:slug.hbs](/docs/templates#page-hbs), [page.hbs](/docs/templates#page-hbs), [post.hbs](/docs/templates#post-hbs)", "4-4": ".page-template, .tag-:slug", "4-3": "{post}", "5-0": "[tag](doc:tag-context)", "5-1": "/tag/:slug/", "5-2": "[tag-:slug.hbs](/docs/templates#tags-hbs), [tag.hbs](/docs/templates#tags-hbs), [index.hbs](/docs/templates#index-hbs)", "5-3": "[{post}], {pagination}, {tag}", "5-4": ".tag-template, .tag-:slug", "6-0": "[tag](doc:tag-context), [paged](doc:paged-context)", "6-1": "/tag/:slug/page/2/", "6-2": "[tag-:slug.hbs](/docs/templates#tags-hbs), [tag.hbs](/docs/templates#tags-hbs) or [index.hbs](/docs/templates#index-hbs)", "6-3": "[{post}], {pagination}, {tag}", "6-4": ".tag-template, .tag-:slug, .paged", "7-0": "[author](doc:author-context)", "7-1": "/author/:slug/", "8-0": "[author](doc:author-context), [paged](doc:paged-context)", "9-0": "[private](doc:private-context)", "7-2": "[author-:slug.hbs](/docs/templates#author-hbs), [author.hbs](/docs/templates#author-hbs) or [index.hbs](/docs/templates#index-hbs)", "7-3": "[{post}], {pagination}, {author}", "8-3": "[{post}], {pagination}, {author}", "7-4": ".author-template, .author-:slug", "8-4": ".author-template, .author-:slug .paged", "8-1": "/author/:slug/page/2/", "8-2": "[author-:slug.hbs](/docs/templates#author-hbs), [author.hbs](/docs/templates#author-hbs), [index.hbs](/docs/templates#index-hbs)", "9-3": "{error}", "9-1": "/private/", "9-2": "[private.hbs](/docs/templates#private-hbs)", "9-4": ".private-template", "10-0": "[subscribe](doc:subscribe)", "10-1": "/subscribe/", "10-2": "[subscribe.hbs](/docs/templates#private-hbs)", "10-3": "Documentation in progress ✨", "3-0": "[amp](doc:amp-context)", "3-1": "/:permalink/amp/", "3-3": "{post}", "3-2": "[amp.hbs](doc:amp)", "3-4": ".amp-template" }, "cols": 5, "rows": 11 } [/block]