else if : Alternative Condition Helper
On this page
Summary
Provides alternative conditional branches within an block. Multiple branches can be chained to create complex conditional logic.
Based on: Additional <when> elements in the <choose> structure
Syntax
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
condition |
Expression | Yes | Expression that evaluates to true/false |
Supported Operators
Same as ``:
| Operator | Description | Example |
|---|---|---|
== |
Equality | model.status == 'pending' |
!= |
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
Grade Classification
Data:
doc.Params["model"] = new {
score = 75
};
Output:
<span class="grade-c">C - Average</span>
Order Status
Data:
doc.Params["model"] = new {
status = "processing"
};
Output:
<div class="order-status">
<span class="badge-info">Processing Order</span>
</div>
Age Group Classification
Data:
doc.Params["model"] = new {
age = 17
};
Output:
<p class="teen">Teenager (13-19)</p>
Priority Level with Multiple Conditions
Underlying Implementation
The `` helper compiles to additional <when> elements in the Scryber <choose> structure:
<choose>
<when data-test="">
<!-- First if block -->
</when>
<when data-test="">
<!-- First else if block -->
</when>
<when data-test="">
<!-- Second else if block -->
</when>
<otherwise>
<!-- Final else block -->
</otherwise>
</choose>
Conditions are evaluated in order from top to bottom. Only the first true condition is rendered.
Notes
- Only used within `` blocks
- Can have unlimited `` branches
- Evaluated in order - first true condition wins
- Only one branch is ever rendered
- Must come after
and before - Supports all comparison and logical operators
- Cannot use
!(NOT) operator - use!=or reverse logic instead - Use parentheses for complex expressions:
(a && b) || c