Skip to main content Link Search Menu Expand Document (external link)

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


  <!-- Rendered if condition1 is true -->

  <!-- Rendered if condition1 is false and condition2 is true -->

  <!-- Rendered if condition1 and condition2 are false and condition3 is true -->

  <!-- Rendered if all conditions are false -->


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


  <span class="grade-a">A - Excellent</span>

  <span class="grade-b">B - Good</span>

  <span class="grade-c">C - Average</span>

  <span class="grade-d">D - Below Average</span>

  <span class="grade-f">F - Failing</span>

Data:

doc.Params["model"] = new {
    score = 75
};

Output:

<span class="grade-c">C - Average</span>

Order Status

<div class="order-status">
  
    <span class="badge-success">✓ Shipped</span>
    <p>Tracking: </p>
  
    <span class="badge-info">Processing Order</span>
  
    <span class="badge-warning">Pending Payment</span>
  
    <span class="badge-danger">Cancelled</span>
  
    <span class="badge-secondary">Unknown Status</span>
  
</div>

Data:

doc.Params["model"] = new {
    status = "processing"
};

Output:

<div class="order-status">
  <span class="badge-info">Processing Order</span>
</div>

Age Group Classification


  <p class="child">Child (under 13)</p>

  <p class="teen">Teenager (13-19)</p>

  <p class="adult">Adult (20-64)</p>

  <p class="senior">Senior (65+)</p>

Data:

doc.Params["model"] = new {
    age = 17
};

Output:

<p class="teen">Teenager (13-19)</p>

Priority Level with Multiple Conditions


  <div class="priority-critical">
    <h3>CRITICAL PRIORITY</h3>
  </div>

  <div class="priority-high">
    <h3>High Priority</h3>
  </div>

  <div class="priority-medium">
    <h3>Medium Priority</h3>
  </div>

  <div class="priority-low">
    <h3>Standard Priority</h3>
  </div>


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

See Also