This is a drop-in replacement for Handlebars default #if
with added support for Array checking, context switching, and the following conditionals:
in
- Check for the presence of an item in the given list.not in
- Inverse ofin
- and these standard operators
==
,===
,!=
,!==
,<
,<=
,>
,>=
.
This is the default handlebars behavior.
{{#if property}}
...
{{else}}
...
{{/if}}
{{#if property '===' condition}}
...
{{else}}
...
{{/if}}
{{#if property 'in' [1,2,5]}}
...
{{else}}
...
{{/if}}
Use keywords all
(default), any
, and no
for checking items in an array seperately. Optionally include a propName
to evaluate collections based on their properties.
{{#if 'any' things '>' 5}}
...
{{else}}
...
{{/if}}
{{#if 'all' things 'foo' '>' 5}}
...
{{else}}
...
{{/if}}
You may also include a do
operator to evaluate the block with a different context.
{{#if property 'do' newContext}}
...
{{else}}
...
{{/if}}
{{#if property '==' 5 'do' newContext}}
...
{{else}}
...
{{/if}}
#unless
a full-featured inverse of #if
. Conditions, Array checks and context swiching follow the same syntax.