Field Helpers - Logic
-
and
- compare
-
gt
-
gte
-
ifAny
-
if_gt or ifgt
-
if_gteq or ifgteq
-
if_eq or ifeq
- is
-
isnt
-
lt
-
lte
-
or
-
unless_eq or unlessEq
-
unless_gt or unlessGt
-
unless_gteq or unlessGtEq
-
unless_lt or unlessLt
-
unless_lteq or unlessLtEq
Conditionally render a block if both values are truthy.
Parameters: values string|int
- the values to test against.
Data:
great = true magnificent = true
Template:
{{#and great magnificent}} Next big thing is on the way! {{else}} Never mind :( {{/and}}
Renders to:
Next big thing is on the way!
{{ {{compare}}
Runs selected compare operator against arguments.
Parameters:
- @param left value
- @param operator The operator, must be between quotes ">", "=", "<=", etc...
- @param right value
- @param options option object sent by handlebars
Examples:
{{#compare unicorns "<" ponies}} I knew it, unicorns are just low-quality ponies! {{/compare}}
{{#compare value ">=" 10}} * The value is greater or equal than 10 * {{else}} * The value is lower than 10 * {{/compare}} {{/compare}}
{{#compare (now) ">=" tenancy.startDate}}
{{#compare (now) "<" tenancy.endDate}}
SHOW ME
{{else}}
NOT
{{/compare}}
{{/compare}}
{{ {{gt}}
Conditionally render a block if the value is greater than a given number (If x > y).
Parameters: value string|int
- the value to test against.
Data:
number = 5
Template:
{{#gt number 8}} Next big thing is on the way! {{else}} Never mind :( {{/gt}}
Renders to:
Never mind :(
{{#todo}}Same as if_gt
, consider consolidating{{/todo}}
{{ {{gte}}
Conditionally render a block if the value is greater or equal than a given number (If x >= y).
Parameters: value string|int
- the value to test against.
number = 5
Template:
{{#gte number 5}} Next big thing is on the way! {{else}} Never mind :( {{/gte}}
Renders to:
Next big thing is on the way!
{{#todo}}Same as if_gteq
, consider consolidating{{/todo}}
{ {{{if_gt}}
Conditionally render a block if the value is greater than a given number (If x > y). Parameters:none
{{#if_gt x compare=y}} ... {{/if_gt}}
{{ {{if_gteq}}
Conditionally render a block if the value is greater or equal than a given number (If x >= y).Parameters: none
{{#if_gteq x compare=y}} ... {{/if_gteq}}
{{ {{is}}
Conditionally render a block if the condition is true (if x = y).
Parameters: string|int
(the value to test against) Default: undefined
E example #1:
Data:
--- number = 5 ---
Template:
{{#is number 5}} Next big thing is on the way! {{else}} Never mind :( {{/is}}
Renders to:
Next big thing is on the way!
Es example #2:
If you are using data from YAML front matter or any specified JSON
and/or YAML
source files will get passed through to the context in your templates.
Data and Templates:
--- page: title: About Us --- {{#is page.title "Home"}} <h1> About Us </h1> {{else}} <h1> My Blog </h1> {{/is}}
Renders to:
<h1> About Us </h1>
{{ {{ifeq}}
Alias for is
. Considering consolidating
Conditionally render a block if the condition is true (If x = y).
Parameters: none
{{#ifeq x compare=y}} ... {{/ifeq}}
{{ {{isnt}}
Conditionally render a block if the condition is false. Opposite of is
.
Parameters: value string|int
- the value to test against.
Data:
number = 5
Template:
{{#isnt number 5}} Next big thing is on the way! {{else}} Never mind :( {{/isnt}}
Renders to:
Never mind :(
{{ {{lt}}
Conditionally render a block if the value is less than a given number. Opposite of gt
.
Parameters: value string|int
- the value to test against.
Data:
number = 5
Template:
{{#lt number 3}} Next big thing is on the way! {{else}} Never mind :( {{/lt}}
Renders to:
Never mind :(
{{ {{lte}}
Conditionally render a block if the value is less or equal than a given number. Opposite of gte
.
Parameters: value string|int
- the value to test against.
Data:
number = 5
Template:
{{#lte number 5}} Next big thing is on the way! {{else}} Never mind :( {{/lte}}
Renders to:
Next big thing is on the way!
{{ {{or}}
Conditionally render a block if one of the values is truthy.
Parameters: values string|int
- the values to test against.
Data:
great = no magnificent = true
Template:
{{#or great magnificent}} Next big thing is on the way! {{else}} Never mind :( {{/or}}
Renders to:
Next big thing is on the way!
{ [{{unless_eq}}
Alias for isnt
Conditionally render a block if the condition is false (Unless x = y). Opposite of is
.
Parameters: none
{{#unless_eq x compare=y}} ... {{/unless_eq}}
{{ {{unless_gt}}
Unless greater than (Unless x > y) Parameters: none
{{#unless_gt x compare=y}} ... {{/unless_gt}}
{{ {{unless_gteq}}
"Unless x >= y". Render block, unless given value is greater than or equal to.
Parameters: none
{{#unless_gteq x compare=y}} ... {{/unless_gteq}}
{{ {{unless_lt}}
Render block, unless value is less than a given number (Unless x < y).
Parameters: none
{{#unless_lt x compare=y}} ... {{/unless_lt}}
{{ {{unless_lteq}}
Render block, unless value is less than or equal to a given number (Unless x <= y).
Parameters: none
{{#unless_lteq x compare=y}} ... {{/unless_lteq}}