{{#if(expression)}}
{{#if(EXPRESSION)}}FN{{else}}INVERSE{{/if}}
Renders FN if EXPRESSION is truthy or INVERSE if EXPRESSION
is falsey. Both FN and INVERSE will be rendered with the
current scope.
{{#if(person.isAwake())}} Hello {{/if}}
Parameters
- EXPRESSION
{KeyLookup Expression|Call Expression}:A lookup expression that will provide a truthy or falsey value.
- FN
{sectionRenderer(context, helpers)}:A subsection that can be optionally rendered.
- INVERSE
{sectionRenderer(context, helpers)}:An optional subsection that will be rendered if
EXPRESSIONis falsey and {{else}} is used.
Use
{{#if(key)}} provides explicit conditional truthy tests.
For example, this template:
{{#if(user.isFemale)}}
{{#if(user.isMarried)}}
Mrs
{{/if}}
{{#if(user.isSingle)}}
Miss
{{/if}}
{{/if}}
Rendered with:
{ user: { isFemale: true, isMarried: true } }
Results in:
Mrs
If can be used with {{else}} too. For example,
{{#if(user.isFemale)}}
{{#if(user.isMarried)}}
Mrs
{{else}}
Miss
{{/if}}
{{/if}}
Rendered with:
{ user: { isFemale: true, isMarried: false } }
Results in:
Miss