Conditionals Using conditional statements inside templates Guide

Conditionals

Control Structures

Templates support common control structures like if, elseif and else to handle branching paths in your template.

{#if isEven number}
Even
{else if isZero number}
Zero
{else}
Odd
{/if}

Conditional Helpers

For a full list of comparators view the dedicated section on comparison helpers

Existence

You can use exists and isEmpty to handle value existence. Values are checked against the isEmpty utility.

{#if exists valueToCheck}
Value exists
{/if}
{#if isEmpty collectionToCheck}
Collection is empty
{/if}

Equality

You can use is not, isExactly and isNotExactly helpers to compare values

Exactly helpers use === comparison while is and not use ==

{#if is valueA valueB}
Values are equal
{/if}
{#if not isEven number}
Odd
{else}
Even
{/if}

Comparisons

You can use greaterThan, lessThan, greaterThanEquals, lessThanEquals to compare numeric values

{#if greaterThan numberA numberB}
A is greater than B
{/if}
{#if lessThanEquals numberA numberB}
A is less than or equal to B
{/if}