Built-in predicates¶
A predicate is a trailing path segment ending with a question mark (?). A predicate "queries" the value obtained by resolving preceding path segments and returns true or false.
Note that a question mark (?) is not a valid identifier character. If a variable or property contains a literal ?, bracket notation must be used: foo["bar?"].
array?¶
Resolves to true if the value is an array, or false otherwise.
blank?¶
Resolves to true if the value is null, a string containing only whitespace, or an empty string, array or hash.
defined?¶
Resolves to true if the value is the the special result Nothing. Undefined variables resolve to Nothing, as do math expressions that can't produce a numeric value.
{%- assign
x = null,
y = nosuchthing,
z = {},
-%}
{{ x.defined? }}
{{ y.defined? }}
{{ z.foo.defined? }}
empty?¶
Resolves to true if the value is null or an empty string, array or hash.
number?¶
Resolves to true if the value is a number type.
numeric?¶
Resolves to true if the value is a number type or can be coerced to a number.
object?¶
Resolves to true if the value is an object (aka hash, dictionary or mapping).
string?¶
Resolves to true if the value is a string type.
null?¶
Resolves to true if the value is null.