Logical HelpersAPI reference for logical template helperstoggle-leftAPI Reference
Categories

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

Name Type Description
a any The 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

Name Type Description
a any The 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

Name Type Description
a array The 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

Name Type Description
a any First value to check
b any Second 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

Name Type Description
a any First value to check
b any Second 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

Name Type Description
expr any The expression to evaluate
trueExpr any Value to return if expr is truthy
falseExpr any Value 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>

default

Returns the fallback value if the first value is null or undefined, otherwise returns the first value.

Template Syntax

{default valueToCheck fallbackValue}

Parameters

Name Type Description
value any The value to check
fallback any The fallback value to use if value is null/undefined

Returns

The original value if not null/undefined, otherwise the fallback value.

Example

<p>Welcome, {default user.name 'Guest'}!</p>
<p>Items per page: {default settings.pageSize 10}</p>

Note

Uses nullish coalescing (??) internally, so only null and undefined trigger the fallback. Other falsy values like 0, false, or '' will not use the fallback.

Examples

Previous
Debug
Next
Numeric