has
Reports whether a collection contains something, and what 'contains' means depends on the shape of the value.
For a plain slice, a single parameter is the element to look for, and Has is true when any element equals it. For a slice of maps, the first parameter is a field key and the rest are candidate values, so Has is true when any item's field equals any of those values. For a map with one parameter, Has tests only whether the key exists (the stored value is ignored, so a key mapped to false still counts as present). For a map with a key plus one or more values, Has is true when the key exists and its value equals any of the given values.
Matching is exact on type, so an integer element is not found by a string parameter of the same digits.
any[]anyanyReports whether a plain slice contains a given element.
Given
{"tags": ["featured", "sale", "new"]}Template
{{ tags | has:'featured' }}Result
truePasses several candidate values after the field key, so a slice of maps matches when any item's field equals any one of them.
Given
{"items": [{"name": "Coffee", "status": "sold-out"}, {"name": "Tea", "status": "pending"}]}Template
{{ items | has:'status','active','pending' }}Result
trueShows that for a map with a single parameter Has tests only whether the key exists, so a key mapped to false still counts as present.
Given
{"config": {"debug_mode": false, "region": "eu-west-1"}}Template
{{ config | has:'debug_mode' }}Result
trueTests the stored value when given both a key and a value, returning false when the key holds a different value.
Given
{"config": {"region": "eu-west-1"}}Template
{{ config | has:'region','us-east-1' }}Result
falseReports whether any item in a slice of maps has the named field set to the given value.
Given
{"items": [{"name": "Coffee", "status": "sold-out"}, {"name": "Tea", "status": "active"}]}Template
{{ items | has:'status','active' }}Result
true