#if : Conditional Rendering Helper
On this page
Summary
Conditionally render content based on expressions. Supports multiple branches with and.
Based on: <choose>, <when>, and <otherwise> elements for conditional template rendering
Syntax
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
condition |
Expression | Yes | Expression that evaluates to true/false |
Supported Operators
| Operator | Description | Example |
|---|---|---|
== |
Equality | model.status == 'active' |
!= |
Inequality | model.count != 0 |
< |
Less than | model.age < 18 |
<= |
Less than or equal | model.score <= 100 |
> |
Greater than | model.value > 0 |
>= |
Greater than or equal | model.age >= 18 |
&& |
Logical AND | model.age >= 18 && model.hasLicense |
|| |
Logical OR | model.isAdmin || model.isModerator |
Examples
Simple Condition
If-Else
Multiple Conditions
Comparison Operators
Logical Operators
With #each Context
Underlying Implementation
The `` helper compiles to Scryber’s conditional rendering elements:
<choose>
<when data-test="">
<!-- Content when true -->
</when>
<when data-test="">
<!-- Content for else if -->
</when>
<otherwise>
<!-- Content for else -->
</otherwise>
</choose>
This structure allows Scryber to evaluate conditions at databinding time and only render the matching branch.
Notes
- Expressions are evaluated at databinding time
- Falsy values:
false,null,0, empty string - Truthy values: everything else
- Use parentheses for complex expressions:
(a && b) || c - Cannot use
!(NOT) operator - use!=or reverse logic instead - Multiple `` branches are supported
- Only one branch is rendered in the output