Context helpers that extend the core Dust.js templating system with conditional logic, mathematical operations, and iteration utilities.
Conditional logic helpers that create complex template logic with type-safe comparisons and multiple test scenarios. The select/truth test system enables sophisticated conditional rendering patterns.
Groups truth tests and outputs the first one that passes, providing structured conditional logic for templates.
/**
* Groups truth tests and outputs the first match
* @param key - Value to use as left-hand side of comparisons (optional)
* @param type - Coerce all comparison keys to this type (optional)
*/
{@select key="comparison_value" type="coercion_type"}
<!-- Truth test helpers go here -->
{/select}Usage Examples:
// Basic select with key
{@select key="{userStatus}"}
{@eq value="active"}User is active{/eq}
{@eq value="inactive"}User is inactive{/eq}
{@eq value="pending"}User is pending approval{/eq}
{/select}
// Select with type coercion
{@select key="{userAge}" type="number"}
{@lt value="18"}Minor{/lt}
{@gte value="18"}Adult{/gte}
{/select}
// Select without global key (each truth test provides its own key)
{@select}
{@eq key="{status}" value="published"}Content is published{/eq}
{@eq key="{featured}" value="true"}Content is featured{/eq}
{/select}Comparison helpers that test conditions and render content based on the results. All truth tests can be used standalone or within {@select} blocks.
/**
* Equality test helper
* @param key - Left-hand side value (optional if within @select)
* @param value - Right-hand side value for comparison (required)
* @param type - Type coercion override (optional)
*/
{@eq key="left_value" value="right_value" type="coercion_type"}
Content when values are equal
{:else}
Content when values are not equal
{/eq}
/**
* Inequality test helper
* @param key - Left-hand side value (optional if within @select)
* @param value - Right-hand side value for comparison (required)
* @param type - Type coercion override (optional)
*/
{@ne key="left_value" value="right_value" type="coercion_type"}
Content when values are not equal
{:else}
Content when values are equal
{/ne}
/**
* Less than test helper
* @param key - Left-hand side value (optional if within @select)
* @param value - Right-hand side value for comparison (required)
* @param type - Type coercion override (optional)
*/
{@lt key="left_value" value="right_value" type="coercion_type"}
Content when left < right
{:else}
Content when left >= right
{/lt}
/**
* Less than or equal test helper
* @param key - Left-hand side value (optional if within @select)
* @param value - Right-hand side value for comparison (required)
* @param type - Type coercion override (optional)
*/
{@lte key="left_value" value="right_value" type="coercion_type"}
Content when left <= right
{:else}
Content when left > right
{/lte}
/**
* Greater than test helper
* @param key - Left-hand side value (optional if within @select)
* @param value - Right-hand side value for comparison (required)
* @param type - Type coercion override (optional)
*/
{@gt key="left_value" value="right_value" type="coercion_type"}
Content when left > right
{:else}
Content when left <= right
{/gt}
/**
* Greater than or equal test helper
* @param key - Left-hand side value (optional if within @select)
* @param value - Right-hand side value for comparison (required)
* @param type - Type coercion override (optional)
*/
{@gte key="left_value" value="right_value" type="coercion_type"}
Content when left >= right
{:else}
Content when left < right
{/gte}Usage Examples:
// Standalone truth tests
{@eq key="{user.role}" value="admin"}
<div class="admin-panel">Admin Controls</div>
{/eq}
{@gt key="{score}" value="90"}
<span class="grade-a">Excellent!</span>
{:else}
<span class="grade-lower">Keep trying</span>
{/gt}
// Within select blocks
{@select key="{priority}" type="number"}
{@eq value="1"}High Priority{/eq}
{@eq value="2"}Medium Priority{/eq}
{@eq value="3"}Low Priority{/eq}
{/select}Special helpers that work within {@select} blocks to handle complex conditional scenarios.
/**
* Any helper - renders if at least one truth test in the parent @select passes
* Must be used inside a @select block
*/
{@any}
Content to show if any condition matched
{/any}
/**
* None helper - renders if no truth tests in the parent @select pass
* Must be used inside a @select block
*/
{@none}
Content to show if no conditions matched
{/none}Usage Examples:
{@select key="{userType}"}
{@eq value="premium"}Premium Features Available{/eq}
{@eq value="pro"}Pro Features Available{/eq}
{@any}
<p>You have special account privileges</p>
{/any}
{@none}
<p>Standard account features only</p>
{/none}
{/select}
// Complex example with multiple conditions
{@select key="{user.status}"}
{@eq value="active"}
{@select key="{user.subscription}"}
{@eq value="premium"}Premium Active User{/eq}
{@eq value="basic"}Basic Active User{/eq}
{@none}Active User - No Subscription{/none}
{/select}
{/eq}
{@eq value="inactive"}Inactive User{/eq}
{@none}Unknown User Status{/none}
{/select}All comparison helpers support automatic type coercion to ensure consistent comparisons:
number: Converts values using +valuestring: Converts values using String(value)boolean: Converts values to boolean ('false' string becomes false)date: Converts values using new Date(value)Type Coercion Examples:
// String comparison
{@select key="{userId}" type="string"}
{@eq value="123"}User found{/eq}
{/select}
// Numeric comparison
{@select key="{age}" type="number"}
{@gte value="21"}Can drink{/gte}
{@lt value="21"}Too young{/lt}
{/select}
// Boolean comparison
{@select key="{isEnabled}" type="boolean"}
{@eq value="true"}Feature is enabled{/eq}
{@eq value="false"}Feature is disabled{/eq}
{/select}Error Handling:
Truth Test Helpers (eq, ne, lt, lte, gt, gte):
"{@helperName}: No key specified" and skips renderingundefined for comparisonSelect Helper:
"{@select}: Missing body block"undefined and continues processingAny/None Helpers:
"{@any}: Must be used inside a {@select} block""{@any}: Must not be nested inside {@any} or {@none} block" and skips renderingLogging:
All error and warning messages use the dust logging system:
dust.log(helperName, message, "WARN") for non-critical issuesdust.log(helperName, message, "ERROR") for critical violationsInstall with Tessl CLI
npx tessl i tessl/npm-dustjs-helpers