Template helper if

bauplan.helpers

Overrides Handlebars.helpers.if

No operator

Truthiness - standard Handlebars if helper behaviour

{{#if "foo"}}Yes{{/if}} -> "Yes"

{{#if ""}}Yes{{else}}No{{/if}} -> "No"

==

‘Truthy’ equality

{{#if "1" "==" 1}}Yes{{/if}} -> "Yes"

{{#if "1" "==" "2"}}Yes{{else}}No{{/if}} -> "No"

===

Strict equality

{{#if "1" "===" "1"}}Yes{{/if}} -> "Yes"

{{#if "1" "===" 1}}Yes{{else}}No{{/if}} -> "No"

!=

‘Truthy’ inequality

{{#if "1" "!=" "2"}}Yes{{/if}} -> "Yes"

{{#if "1" "!=" 1}}Yes{{else}}No{{/if}} -> "No"

!==

Strict inequality

{{#if "1" "!==" 1}}Yes{{/if}} -> "Yes"

{{#if "1" "!==" "1"}}Yes{{else}}No{{/if}} -> "No"

<

Less than

{{#if 1 "<" 2}}Yes{{/if}} -> "Yes"

>

More than

{{#if 2 ">" 1}}Yes{{/if}} -> "Yes"

<

Less than or equal

{{#if 1 "<=" 1}}Yes{{/if}} -> "Yes"

>

More than or equal

{{#if 1 ">=" 1}}Yes{{/if}} -> "Yes"

&&

And operator

{{#if "foo" "&&" "bar"}}Yes{{/if}} -> "Yes"

{{#if "foo" "&&" "bar" "&&" "baz"}}Yes{{/if}} -> "Yes"

{{#if "foo" "&&" "bar" "&&" ""}}Yes{{else}}No{{/if}} -> "No"

NB. You cannot mix different operators See also all

||

Or operator

{{#if "" "||" "bar"}}Yes{{/if}} -> "Yes"

{{#if "foo" "||" "" "||" "baz"}}Yes{{/if}} -> "Yes"

{{#if "" "||" 0 "||" ""}}Yes{{else}}No{{/if}} -> "No"

NB. You cannot mix different operators See also or

is

Lodash is* methods

{{#if "foo" "is" "String"}}Yes{{/if}} -> "Yes"

Method has first letter uppercased automatically

{{#if "foo" "is" "string"}}Yes{{/if}} -> "Yes"

constructor

{{#if "foo" "constructor" "String"}}Yes{{/if}} -> "Yes"

{{#if "foo" "constructor" "string"}}Yes{{else}}No{{/if}} -> "No"

typeof

{{#if "foo" "typeof" "string"}}Yes{{/if}} -> "Yes"

{{#if "foo" "typeof" "String"}}Yes{{else}}No{{/if}} -> "No"

has

{{#if "foo" "has" "oo"}}Yes{{/if}} -> "Yes"

Also aliased to contains

{{#if "foo" "contains" "oo"}}Yes{{/if}} -> "Yes"

See also has

matches

{{#if "foo" "matches" "fo{2,}"}}Yes{{/if}}

Also aliased to match

{{#if "foo" "match" "fo{2,}"}}Yes{{/if}}

See also match

in

{{#if "foo" "in" "foo" "bar" "baz"}}Yes{{/if}} -> "Yes"

{{#if "fo" "in" "foo" "bar" "baz"}}Yes{{else}}No{{/if}} -> "No"

matchesin

{{#if "foo" "matchesin" "fo" "bar" "daz"}}Yes{{/if}} -> "Yes"

{{#if "foo" "matchesin" "fo\b" "bar" "daz"}}Yes{{else}}No{{/if}} -> "No"

Also aliased to matchin

{{#if "foo" "matchin" "fo" "bar" "daz"}}Yes{{/if}} -> "Yes"

matchesall

{{#if "foo" "matchesall" "f.{2}" "o+"}}Yes{{/if}} -> "Yes"

{{#if "foo" "matchesin" "f.{2}" "\bo+"}}Yes{{else}}No{{/if}} -> "No"

Also aliased to matchin

{{#if "foo" "matchall" "f.{2}" "o+"}}Yes{{/if}} -> "Yes"

Extends

  • Handlebars.helpers
Source:
Parameters:
Name Type Attributes Description
0 *

Item to compare

1 string <optional>

Operator

2 * <optional>

Item to be compared to

3.​.​.​ * <optional>
<repeatable>

See individual operators to see how further param works