{"_id":"5937b2388e8d9b002f1df29c","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":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0.0"},"__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-05-18T12:13:30.183Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":32,"body":"[block:html]\n{\n  \"html\": \"<div class=\\\"github-deeplinks\\\">\\n    <a href=\\\"https://github.com/TryGhost/Ghost/blob/master/core/server/helpers/twitter_url.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/twitter_url_spec.js\\\"><i class=\\\"fa fa-check-square-o fa-right\\\"></i>Tests</a>\\n</div>\"\n}\n[/block]\nUsage: `{{twitter_url}}` or `{{twitter_url :::at:::blog.twitter}}` or `{{twitter_url \"@MyFavouriteUser\"}}`\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"[Output](/docs/helpers#section-output), [Ghost](/docs/helpers#section-ghost)\",\n    \"h-0\": \"Type\",\n    \"h-1\": \"Parameters\",\n    \"h-2\": \"Attributes\",\n    \"0-2\": \"n/a\",\n    \"0-1\": \"twitter username (string) (optional)\"\n  },\n  \"cols\": 3,\n  \"rows\": 1\n}\n[/block]\n### Description\n\nThis helper exists to make it easy to output a URL for a twitter account. Ghost has access to twitter usernames for both users and for the blog itself. When used without passing a username, the helper will look for a twitter username in the current template context, and then fallback to using [email protected]`. \n\nIf there is no twitter username set, the helper will output nothing at all.\n\nIf you pass a variable or string to the helper, it will concatenate the value with the full url for a twitter page. If you pass the helper a string which starts with `@` it will remove it to generate what twitter considers to be the \"canonical\" url.\n\n\n### Examples\n\nOutput the author's twitter, using an `author` block:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{{#foreach posts}}\\n  {{#author}}\\n    {{#if twitter}}<a href=\\\"{{twitter_url}}\\\">{{twitter}}</a>{{/if}}\\n  {{/author}}\\n{{/foreach}}\",\n      \"language\": \"handlebars\"\n    },\n    {\n      \"code\": \"<a href=\\\"https://twitter.com/mytwitter\\\">@mytwitter</a>\",\n      \"language\": \"handlebars\"\n    }\n  ]\n}\n[/block]\nOutput the author's facebook, without an `author` block:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{{#post}}\\n\\t<h1>{{title}}</h1>\\n  <p class=\\\"meta\\\">Written by {{author}}, follow me on <a href=\\\"{{twitter_url author.twitter}}\\\">{{twitter}}</a>!</p>\\n{{/post}}\",\n      \"language\": \"handlebars\"\n    },\n    {\n      \"code\": \"<h1>My Post</h1>\\n<p class=\\\"meta\\\">Written by <a href=\\\"/author/author-slug\\\">Author Name</a>, follow me on <a href=\\\"https://twitter.com/mytwitter\\\">@mytwitter</a>!</p>\\n\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nOutput the blog's twitter url in the footer:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<footer class=\\\"site-footer clearfix\\\">\\n  <section class=\\\"copyright\\\">\\n    <a href=\\\"[email protected]}}\\\">[email protected]}}</a> &copy; {{date format=\\\"YYYY\\\"}}\\n  </section>\\n  <section class=\\\"twitter\\\">\\n  \\t{{!-- @blog.twitter is the default, so we don't have to specify --}}\\n    <a href=\\\"{{twitter_url}}\\\">[email protected]}}</a>\\n  </section>\\n  <section class=\\\"poweredby\\\">\\n    Proudly published with <a href=\\\"https://ghost.org\\\">Ghost</a>\\n  </section>\\n</footer>\",\n      \"language\": \"handlebars\"\n    },\n    {\n      \"code\": \"<footer class=\\\"site-footer clearfix\\\">\\n  <section class=\\\"copyright\\\">\\n    <a href=\\\"https://my-ghost-blog.com\\\">My Ghost Blog</a> &copy; 2016\\n  </section>\\n  <section class=\\\"twitter\\\">\\n    <a href=\\\"https://twitter.com/myghostblog\\\">@myghostblog</a>\\n  </section>\\n  <section class=\\\"poweredby\\\">\\n    Proudly published with <a href=\\\"https://ghost.org\\\">Ghost</a>\\n  </section>\\n</footer>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nOutput a link to any twitter page:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<p>I'm a real fan of <a href=\\\"{{twitter_url \\\"@Ghostbusters\\\"}}\\\">Ghostbusters!</a></p>\",\n      \"language\": \"handlebars\"\n    },\n    {\n      \"code\": \"<p>I'm a real fan of <a href=\\\"https://twitter.com/Ghostbusters\\\">Ghostbusters!</a></p>\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]","excerpt":"`{{twitter_url}}` Helper - output a full url for a twitter username.","slug":"twitter_url","type":"basic","title":"twitter_url"}

twitter_url

`{{twitter_url}}` Helper - output a full url for a twitter username.

[block:html] { "html": "<div class=\"github-deeplinks\">\n <a href=\"https://github.com/TryGhost/Ghost/blob/master/core/server/helpers/twitter_url.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/twitter_url_spec.js\"><i class=\"fa fa-check-square-o fa-right\"></i>Tests</a>\n</div>" } [/block] Usage: `{{twitter_url}}` or `{{twitter_url @blog.twitter}}` or `{{twitter_url "@MyFavouriteUser"}}` [block:parameters] { "data": { "0-0": "[Output](/docs/helpers#section-output), [Ghost](/docs/helpers#section-ghost)", "h-0": "Type", "h-1": "Parameters", "h-2": "Attributes", "0-2": "n/a", "0-1": "twitter username (string) (optional)" }, "cols": 3, "rows": 1 } [/block] ### Description This helper exists to make it easy to output a URL for a twitter account. Ghost has access to twitter usernames for both users and for the blog itself. When used without passing a username, the helper will look for a twitter username in the current template context, and then fallback to using [email protected]`. If there is no twitter username set, the helper will output nothing at all. If you pass a variable or string to the helper, it will concatenate the value with the full url for a twitter page. If you pass the helper a string which starts with `@` it will remove it to generate what twitter considers to be the "canonical" url. ### Examples Output the author's twitter, using an `author` block: [block:code] { "codes": [ { "code": "{{#foreach posts}}\n {{#author}}\n {{#if twitter}}<a href=\"{{twitter_url}}\">{{twitter}}</a>{{/if}}\n {{/author}}\n{{/foreach}}", "language": "handlebars" }, { "code": "<a href=\"https://twitter.com/mytwitter\">@mytwitter</a>", "language": "handlebars" } ] } [/block] Output the author's facebook, without an `author` block: [block:code] { "codes": [ { "code": "{{#post}}\n\t<h1>{{title}}</h1>\n <p class=\"meta\">Written by {{author}}, follow me on <a href=\"{{twitter_url author.twitter}}\">{{twitter}}</a>!</p>\n{{/post}}", "language": "handlebars" }, { "code": "<h1>My Post</h1>\n<p class=\"meta\">Written by <a href=\"/author/author-slug\">Author Name</a>, follow me on <a href=\"https://twitter.com/mytwitter\">@mytwitter</a>!</p>\n", "language": "html" } ] } [/block] Output the blog's twitter url in the footer: [block:code] { "codes": [ { "code": "<footer class=\"site-footer clearfix\">\n <section class=\"copyright\">\n <a href=\"[email protected]}}\">[email protected]}}</a> &copy; {{date format=\"YYYY\"}}\n </section>\n <section class=\"twitter\">\n \t{{!-- @blog.twitter is the default, so we don't have to specify --}}\n <a href=\"{{twitter_url}}\">[email protected]}}</a>\n </section>\n <section class=\"poweredby\">\n Proudly published with <a href=\"https://ghost.org\">Ghost</a>\n </section>\n</footer>", "language": "handlebars" }, { "code": "<footer class=\"site-footer clearfix\">\n <section class=\"copyright\">\n <a href=\"https://my-ghost-blog.com\">My Ghost Blog</a> &copy; 2016\n </section>\n <section class=\"twitter\">\n <a href=\"https://twitter.com/myghostblog\">@myghostblog</a>\n </section>\n <section class=\"poweredby\">\n Proudly published with <a href=\"https://ghost.org\">Ghost</a>\n </section>\n</footer>", "language": "html" } ] } [/block] Output a link to any twitter page: [block:code] { "codes": [ { "code": "<p>I'm a real fan of <a href=\"{{twitter_url \"@Ghostbusters\"}}\">Ghostbusters!</a></p>", "language": "handlebars" }, { "code": "<p>I'm a real fan of <a href=\"https://twitter.com/Ghostbusters\">Ghostbusters!</a></p>", "language": "html" } ] } [/block]