{"_id":"5937b2388e8d9b002f1df285","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","parentDoc":null,"user":"542c5cfcddd3190e00228849","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":["5436f6e5b7cf0e1c0020dce1"],"next":{"pages":[],"description":""},"createdAt":"2014-10-04T19:33:39.362Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"never","params":[],"url":""},"isReference":false,"order":29,"body":"[block:html]\n{\n  \"html\": \"<div class=\\\"github-deeplinks\\\">\\n    <a href=\\\"https://github.com/TryGhost/Ghost/blob/master/core/server/helpers/encode.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/encode_spec.js\\\"><i class=\\\"fa fa-check-square-o fa-right\\\"></i>Tests</a>\\n</div>\"\n}\n[/block]\nUsage: `{{encode value}}`\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Type\",\n    \"h-1\": \"Parameters\",\n    \"h-2\": \"Attributes\",\n    \"0-0\": \"[Output](/docs/helpers#section-output), \\n[Formatting](/docs/helpers#section-formatting),\\n[Ghost](/docs/helpers#section-ghost)\",\n    \"0-1\": \"* value (string)\",\n    \"0-2\": \"n/a\"\n  },\n  \"cols\": 3,\n  \"rows\": 1\n}\n[/block]\n### Description\n\n`{{encode}}` is a simple output helper which will encode a given string so that it can be used in a URL.\n\nThe most obvious example of where this is useful is shown in Casper's `post.hbs`, for outputting a twitter share link:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<a class=\\\"icon-twitter\\\" href=\\\"http://twitter.com/share?text={{encode title}}&url={{url absolute=\\\"true\\\"}}\\\"\\n    onclick=\\\"window.open(this.href, 'twitter-share', 'width=550,height=235');return false;\\\">\\n    <span class=\\\"hidden\\\">Twitter</span>\\n</a>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nWithout using the `{{encode}}` helper on the post's title, the spaces and other punctuation in the title would not be handled correctly.","excerpt":"`{{encode}}` Helper - Encode a value using for using as part of a URL encodeURIComponent","slug":"encode","type":"basic","title":"encode"}

encode

`{{encode}}` Helper - Encode a value using for using as part of a URL encodeURIComponent

[block:html] { "html": "<div class=\"github-deeplinks\">\n <a href=\"https://github.com/TryGhost/Ghost/blob/master/core/server/helpers/encode.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/encode_spec.js\"><i class=\"fa fa-check-square-o fa-right\"></i>Tests</a>\n</div>" } [/block] Usage: `{{encode value}}` [block:parameters] { "data": { "h-0": "Type", "h-1": "Parameters", "h-2": "Attributes", "0-0": "[Output](/docs/helpers#section-output), \n[Formatting](/docs/helpers#section-formatting),\n[Ghost](/docs/helpers#section-ghost)", "0-1": "* value (string)", "0-2": "n/a" }, "cols": 3, "rows": 1 } [/block] ### Description `{{encode}}` is a simple output helper which will encode a given string so that it can be used in a URL. The most obvious example of where this is useful is shown in Casper's `post.hbs`, for outputting a twitter share link: [block:code] { "codes": [ { "code": "<a class=\"icon-twitter\" href=\"http://twitter.com/share?text={{encode title}}&url={{url absolute=\"true\"}}\"\n onclick=\"window.open(this.href, 'twitter-share', 'width=550,height=235');return false;\">\n <span class=\"hidden\">Twitter</span>\n</a>", "language": "html" } ] } [/block] Without using the `{{encode}}` helper on the post's title, the spaces and other punctuation in the title would not be handled correctly.