Usage:
{{#has tag="value1,value2" author="value"}}
{{#has slug=../slug}}
{{#has number="nth:3"}}
{{#has any="twitter, facebook"}}
{{#has all="twitter, facebook"}}
{{#has}}
is like {{#if}}
but with the ability to do more than test a boolean. It allows theme developers to ask questions about the current context and provide more flexibility for creating different layouts.
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. In addition, it is possible to do {{else has ...}}
, to chain together multiple options like a switch statement.
{{#has}}
helper can be combined with internal tags, to display different information for different types of posts. E.g. implementing a link-style post by adding an internal tag of #link
and using the has helper to detect it:
{{#has}}
helper supports four different types of “questions”:
tag="tag name"
. You can pass multiple attributes, and the {{#has}}
helper will always treat this as an OR
.
E.g. You can look for a post with a slug of “welcome” OR a tag of “getting started”:
{{#has}}
helper to find out if the post has a particular tag or author. Both the tag
and author
attributes take a comma separated list. If you pass multiple values separated by a comma, these will be treated as an OR.
author
and tag
attribute accepts a counting value. You can choose between:
count:[number]
count:>[number]
count:<[number]
{{#has}}
helper to do an exact match. Similarly for all objects that have an ID.
You can either pass the {{#has}}
helper a string wrapped in quotes, or a path to a data value from else where in the template data. For example, the following code does an exact match on the string “welcome”. If the post’s slug is the same, the code inside the has helper will execute.
any
comparison will return true if any one of the properties is set in the current context, with support for paths and globals:
all
comparison will return true only when all of the properties are set:
{{#foreach}}
loop of any kind, you have access to two special data variables called @index
and @number
. @index
contains the 0-based index or count of the loop, and @number
contains a 1-based index. That is each time around the loop these values increase by 1, but @index
starts at 0, and @number
starts at 1.
The {{#has}}
helper will let you check which number/index of the iteration you are on using the 3 different styles of matching shown above. For example, if you have a list of posts and want to inject a special widget partial every 3rd post, you could do so using the nth:3
pattern:
{{#has}}
helpers: