{"category":{"version":"58c81e8e693cdd1900606acf","project":"542fe92a5eceb608003fddc8","_id":"58c81e8e693cdd1900606ad3","__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"},"parentDoc":null,"project":"542fe92a5eceb608003fddc8","user":"542c5cfcddd3190e00228849","version":{"__v":1,"_id":"58c81e8e693cdd1900606acf","project":"542fe92a5eceb608003fddc8","createdAt":"2017-03-14T16:47:10.620Z","releaseDate":"2017-03-14T16:47:10.620Z","categories":["58c81e8e693cdd1900606ad0","58c81e8e693cdd1900606ad1","58c81e8e693cdd1900606ad2","58c81e8e693cdd1900606ad3","58c81e8e693cdd1900606ad4","58c81e8e693cdd1900606ad5"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"0.11.7","version":"0.11.7"},"_id":"58c81e8e693cdd1900606aee","__v":0,"updates":["55364f5be1b9c10d00d39da0"],"next":{"pages":[],"description":""},"createdAt":"2014-10-04T19:35:17.273Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"never","params":[],"url":""},"isReference":false,"order":35,"body":"[block:html]\n{\n  \"html\": \"<div class=\\\"github-deeplinks\\\">\\n    <a href=\\\"https://github.com/TryGhost/Ghost/blob/0.10.0/core/server/helpers/has.js\\\"><i class=\\\"fa fa-github-alt fa-right\\\"></i>Source</a>\\n    <a href=\\\"https://github.com/TryGhost/Ghost/blob/0.10.0/core/test/unit/server_helpers/has_spec.js\\\" class=\\\"fa fa-check-square-o fa-right\\\">Tests</a>\\n</div>\"\n}\n[/block]\nUsage: `{{#has tag=\"value1,value2\" author=\"value\"}}`\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Types\",\n    \"h-1\": \"Parameters\",\n    \"h-2\": \"Attributes\",\n    \"0-0\": \"[Block](/docs/helpers#section-block), [Ghost](/docs/helpers#section-ghost)\",\n    \"0-1\": \"n/a\",\n    \"0-2\": \"* `tag` (comma separated list)\\n* `author` (comma separated list)\"\n  },\n  \"cols\": 3,\n  \"rows\": 1\n}\n[/block]\n### Description\n\n`{{#has}}` intends to allow theme developers to ask questions about the current context and provide more flexibility for creating different post layouts in Ghost. \n\nLike all block helpers, `{{#has}}` supports adding an `{{else}}` block or using `^` instead of `#` for negation - this means that the `{{#has}}` and `{{else}}` blocks are reversed if you use `{{^has}}` and `{{else}}` instead.\n\n### Example Code\n\nCurrently, the `{{#has}}` helper only allows you to ask questions about a post's author or tags:\n\n\nTo determine if a post has a particular author:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{{#post}}\\n    {{#has author=\\\"Joe Bloggs\\\"}}\\n        ...do something if the author is Joe Bloggs...\\n    {{/has}}\\n{{/post}}\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nTo determine if a post has a particular tag:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{{#post}}\\n    {{#has tag=\\\"photo\\\"}}\\n        ...do something if this post has a tag of photo...\\n    {{else}}\\n        ...do something if this posts doesn't have a tag of photo...\\n    {{/has}}\\n{{/post}}\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nYou can also supply a comma-separated list of tags, which is the equivalent of an OR query, asking if a post has any one of the given tags:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{{#has tag=\\\"photo, video, audio\\\"}}\\n    ...do something if this post has a tag of photo or video or audio...\\n{{else}}\\n    ...do something with other posts...\\n{{/has}}\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nYou can do an AND query by nesting your `{{#has}}` helpers:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{{#has tag=\\\"photo\\\"}}\\n    ...do something if this post has a tag of photo..\\n    {{#has tag=\\\"panorama\\\"}}\\n       ...if the post has both the photo and panorama tags\\n    {{/has}}\\n{{else}}\\n    ...do something with other posts...\\n{{/has}}\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nYou can also do multiple options, a bit like a switch statement by nesting inside of the `{{else}}` part of the helper:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{{#has tag=\\\"photo\\\"}}\\n    ...post has the photo tag...\\n{{else}}\\n    {{#has tag=\\\"video\\\"}}\\n        ...post has the video tag...\\n    {{else}}\\n        {{#has tag=\\\"audio\\\"}}\\n            ...post has the audio tag...\\n        {{else}}\\n            ...post has none of the mentioned tags...\\n        {{/has}}\\n    {{/has}}\\n{{/has}}\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]\nIf you're interested in negating the query, i.e. determining if a post does **not** have a particular tag, this is also possible.\n\nHandlebars has a feature which is available with all block helpers that allows you to do the inverse of the helper by using `^` instead of `#` to start the helper:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{{^has tag=\\\"photo\\\"}}\\n    ...do something if this post does **not** have a tag of photo...\\n{{else}}\\n    ...do something if this posts does have a tag of photo...\\n{{/has}}\",\n      \"language\": \"html\"\n    }\n  ]\n}\n[/block]","excerpt":"`{{has}}` Helper - Test if a post has specific properties","slug":"has","type":"basic","title":"has"}

has

`{{has}}` Helper - Test if a post has specific properties

[block:html] { "html": "<div class=\"github-deeplinks\">\n <a href=\"https://github.com/TryGhost/Ghost/blob/0.10.0/core/server/helpers/has.js\"><i class=\"fa fa-github-alt fa-right\"></i>Source</a>\n <a href=\"https://github.com/TryGhost/Ghost/blob/0.10.0/core/test/unit/server_helpers/has_spec.js\" class=\"fa fa-check-square-o fa-right\">Tests</a>\n</div>" } [/block] Usage: `{{#has tag="value1,value2" author="value"}}` [block:parameters] { "data": { "h-0": "Types", "h-1": "Parameters", "h-2": "Attributes", "0-0": "[Block](/docs/helpers#section-block), [Ghost](/docs/helpers#section-ghost)", "0-1": "n/a", "0-2": "* `tag` (comma separated list)\n* `author` (comma separated list)" }, "cols": 3, "rows": 1 } [/block] ### Description `{{#has}}` intends to allow theme developers to ask questions about the current context and provide more flexibility for creating different post layouts in Ghost. Like all block helpers, `{{#has}}` supports adding an `{{else}}` block or using `^` instead of `#` for negation - this means that the `{{#has}}` and `{{else}}` blocks are reversed if you use `{{^has}}` and `{{else}}` instead. ### Example Code Currently, the `{{#has}}` helper only allows you to ask questions about a post's author or tags: To determine if a post has a particular author: [block:code] { "codes": [ { "code": "{{#post}}\n {{#has author=\"Joe Bloggs\"}}\n ...do something if the author is Joe Bloggs...\n {{/has}}\n{{/post}}", "language": "html" } ] } [/block] To determine if a post has a particular tag: [block:code] { "codes": [ { "code": "{{#post}}\n {{#has tag=\"photo\"}}\n ...do something if this post has a tag of photo...\n {{else}}\n ...do something if this posts doesn't have a tag of photo...\n {{/has}}\n{{/post}}", "language": "html" } ] } [/block] You can also supply a comma-separated list of tags, which is the equivalent of an OR query, asking if a post has any one of the given tags: [block:code] { "codes": [ { "code": "{{#has tag=\"photo, video, audio\"}}\n ...do something if this post has a tag of photo or video or audio...\n{{else}}\n ...do something with other posts...\n{{/has}}", "language": "html" } ] } [/block] You can do an AND query by nesting your `{{#has}}` helpers: [block:code] { "codes": [ { "code": "{{#has tag=\"photo\"}}\n ...do something if this post has a tag of photo..\n {{#has tag=\"panorama\"}}\n ...if the post has both the photo and panorama tags\n {{/has}}\n{{else}}\n ...do something with other posts...\n{{/has}}", "language": "html" } ] } [/block] You can also do multiple options, a bit like a switch statement by nesting inside of the `{{else}}` part of the helper: [block:code] { "codes": [ { "code": "{{#has tag=\"photo\"}}\n ...post has the photo tag...\n{{else}}\n {{#has tag=\"video\"}}\n ...post has the video tag...\n {{else}}\n {{#has tag=\"audio\"}}\n ...post has the audio tag...\n {{else}}\n ...post has none of the mentioned tags...\n {{/has}}\n {{/has}}\n{{/has}}", "language": "html" } ] } [/block] If you're interested in negating the query, i.e. determining if a post does **not** have a particular tag, this is also possible. Handlebars has a feature which is available with all block helpers that allows you to do the inverse of the helper by using `^` instead of `#` to start the helper: [block:code] { "codes": [ { "code": "{{^has tag=\"photo\"}}\n ...do something if this post does **not** have a tag of photo...\n{{else}}\n ...do something if this posts does have a tag of photo...\n{{/has}}", "language": "html" } ] } [/block]