Skip to Content
DocumentationGet Started@else Statement

Overview

The @else statement is used with an @if statement to specify a block of code that will execute if the @if condition is false.

In simple words:

“If this is true, do this. ELSE, do something different.”

Syntax (Generic Form)

@if (condition) { // code if condition is true } @else { // code if condition is false }

How It Works

  1. First, the @if condition is evaluated.

  2. If true, the @if block runs and @else is skipped.

  3. If false, the @else block runs.

Example

serve ( @if (user) { <h1>Welcome, @(user.username)</h1> } @else { <a href="/login">Login</a> } )

Key Points

  • @else does NOT have a condition. It only runs when the @if condition is false.

  • There can be only one @else for each @if.

Last updated on