{"_id":"5937b23b8e8d9b002f1df2ae","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-14T11:03:06.432Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":16,"body":"Use: `{{#is \"private\"}}{{/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\": \"private\",\n    \"0-3\": \"{error}\",\n    \"0-1\": \"/private/\",\n    \"0-2\": \"private.hbs\",\n    \"0-4\": \".private-template\"\n  },\n  \"cols\": 5,\n  \"rows\": 1\n}\n[/block]\n## Description\n\nIf a blog has password protection enabled, then all users are redirected to a page where they are asked to provide a password. When on this page the context is set to `private`.\n\n## Routes\n\nThe `private` context lives at the matching `/private/` route. If the user attempted to visit a specific page, the route will look something like `/private/?r=%2F` and will redirect the user to the url specified in the `r` query parameter after they enter the correct password. This cannot be customised at present.\n\n## Templates\n\nBy default, the `private` context will be rendered using the `private.hbs` file which exists in [/private-blogging/lib/views/](https://github.com/TryGhost/Ghost/blob/0.8.0/core/server/apps/private-blogging/lib/views/private.hbs). This page will be styled to match the Ghost admin panel. \n\nTo customise this page, theme developers can provide their own `private.hbs` file as part of their theme. This will override the default.\n\n## Data\n\nThe `private.hbs` gets access to just one piece of data - an error object which may or may not be set after the password form is submitted. If set, error has an attribute of `message` which contains an explanation of what went wrong with submitting the form.\n\nTo conditionally output the message, first check if error is set:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{{#if error}}\\n  <span class=\\\"error-message\\\">{{error.message}}</span>\\n{{/if}}\",\n      \"language\": \"handlebars\",\n      \"name\": \"private.hbs\"\n    }\n  ]\n}\n[/block]\n## Helpers\n\nThe `private` context makes use of a special `{{input_password}}` helper which outputs a password input with the correct properties, so that the form will work. The `private.hbs` has a couple of requirements in order to make the form work correctly:\n\n* It must contain a form which posts back to the same URL\n* The form must have an input with the name `password` (use the `{{input_password}}` helper)\n* The page must conditionally output any errors to the user\n\n## Example Code\n\nBare minimum code required for the form to work:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<form method=\\\"post\\\">\\n  {{input_password}}\\n  <input type=\\\"submit\\\" />\\n</form>\\n\\n{{#if error}}\\n   {{error.message}}\\n{{/if}}\",\n      \"language\": \"handlebars\",\n      \"name\": \"private.hbs\"\n    }\n  ]\n}\n[/block]","excerpt":"The `private` context","slug":"private-context","type":"basic","title":"private"}

private

The `private` context

Use: `{{#is "private"}}{{/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": "private", "0-3": "{error}", "0-1": "/private/", "0-2": "private.hbs", "0-4": ".private-template" }, "cols": 5, "rows": 1 } [/block] ## Description If a blog has password protection enabled, then all users are redirected to a page where they are asked to provide a password. When on this page the context is set to `private`. ## Routes The `private` context lives at the matching `/private/` route. If the user attempted to visit a specific page, the route will look something like `/private/?r=%2F` and will redirect the user to the url specified in the `r` query parameter after they enter the correct password. This cannot be customised at present. ## Templates By default, the `private` context will be rendered using the `private.hbs` file which exists in [/private-blogging/lib/views/](https://github.com/TryGhost/Ghost/blob/0.8.0/core/server/apps/private-blogging/lib/views/private.hbs). This page will be styled to match the Ghost admin panel. To customise this page, theme developers can provide their own `private.hbs` file as part of their theme. This will override the default. ## Data The `private.hbs` gets access to just one piece of data - an error object which may or may not be set after the password form is submitted. If set, error has an attribute of `message` which contains an explanation of what went wrong with submitting the form. To conditionally output the message, first check if error is set: [block:code] { "codes": [ { "code": "{{#if error}}\n <span class=\"error-message\">{{error.message}}</span>\n{{/if}}", "language": "handlebars", "name": "private.hbs" } ] } [/block] ## Helpers The `private` context makes use of a special `{{input_password}}` helper which outputs a password input with the correct properties, so that the form will work. The `private.hbs` has a couple of requirements in order to make the form work correctly: * It must contain a form which posts back to the same URL * The form must have an input with the name `password` (use the `{{input_password}}` helper) * The page must conditionally output any errors to the user ## Example Code Bare minimum code required for the form to work: [block:code] { "codes": [ { "code": "<form method=\"post\">\n {{input_password}}\n <input type=\"submit\" />\n</form>\n\n{{#if error}}\n {{error.message}}\n{{/if}}", "language": "handlebars", "name": "private.hbs" } ] } [/block]