Guide › Templates

Conditionals

Show one of several branches with @if, @else if and @else.

@if (user.isAdmin) {
  <a href="/admin">Admin</a>
} @else if (user.isEditor) {
  <a href="/edit">Edit</a>
} @else {
  <span>Read only</span>
}

Outside an interactive component the choice is made on the server and costs nothing in the browser. Inside one, the branch switches when the state it reads changes: the old branch's handlers are removed and the new branch is inserted and wired.