Logical Helpers API reference for logical template helpers toggle-left Guide

Logical Helpers

Logical helpers provide utilities for conditional checks and logical operations in templates.

Functions

isEmpty

Checks if a value is empty.

Note: empty includes falsey values like false, 0 undefined etc.

Template Syntax

{#if isEmpty collectionToCheck}
Collection is empty
{/if}

Parameters

NameTypeDescription
aanyThe value to check

Returns

boolean - true if the value is empty, false otherwise.

Example

{#if isEmpty user.posts}
<p>You haven't made any posts yet.</p>
{else}
<ul>
{#each user.posts}
<li>{this.title}</li>
{/each}
</ul>
{/if}

exists

Checks if a value is not empty.

Note: the same conditions as isEmpty apply, all falsey values will return false

Template Syntax

{#if exists valueToCheck}
Value exists
{/if}

Parameters

NameTypeDescription
aanyThe value to check

Returns

boolean - true if the value is not empty, false otherwise.

Example

{#if exists user.name}
<p>Welcome, {user.name}!</p>
{else}
<p>Welcome, guest!</p>
{/if}

hasAny

Checks if an array has any elements.

Template Syntax

{#if hasAny arrayToCheck}
Array has elements
{/if}

Parameters

NameTypeDescription
aarrayThe array to check

Returns

boolean - true if the array has elements, false otherwise.

Example

{#if hasAny searchResults}
<ul>
{#each searchResults}
<li>{this.title}</li>
{/each}
</ul>
{else}
<p>No results found.</p>
{/if}

both

Checks if both a and b are truthy.

Template Syntax

{#if both conditionA conditionB}
Both conditions are true
{/if}

Parameters

NameTypeDescription
aanyFirst value to check
banySecond value to check

Returns

boolean - true if both values are truthy, false otherwise.

Example

{#if both isLoggedIn hasPermission}
<button>Perform Action</button>
{else}
<p>You don't have permission to perform this action.</p>
{/if}

either

Checks if either a or b is truthy.

Template Syntax

{#if either conditionA conditionB}
At least one condition is true
{/if}

Parameters

NameTypeDescription
aanyFirst value to check
banySecond value to check

Returns

boolean - true if either value is truthy, false otherwise.

Example

{#if either isAdmin isModerator}
<button>Edit Content</button>
{else}
<p>You don't have permission to edit this content.</p>
{/if}

maybe

Returns trueExpr if expr is truthy, falseExpr otherwise.

Template Syntax

{maybe condition 'True result' 'False result'}

Parameters

NameTypeDescription
expranyThe expression to evaluate
trueExpranyValue to return if expr is truthy
falseExpranyValue to return if expr is falsy

Returns

The value of trueExpr if expr is truthy, falseExpr otherwise.

Example

<p>The light is {maybe isOn 'on' 'off'}.</p>