sercrod

*else / n-else

Summary

*else marks the fallback branch of an *if / *elseif / *else chain.
When all previous *if and *elseif conditions in the same sibling chain are false, Sercrod renders the *else branch instead.

n-else is a prefix-agnostic alias with identical behavior.

Description

*else is a structural directive that participates in a contiguous sibling chain together with *if and *elseif:

At render time, Sercrod:

  1. Finds the “head” element for the chain by walking left from the current node until it encounters a sibling with *if / n-if. If no such element is found, the *elseif / *else is treated as invalid and ignored.
  2. Starting from the head, walks right across siblings as long as each sibling has at least one of *if, *elseif, or *else (or their n- equivalents) and they share the same parent. The run of such elements forms a single chain; the next *if starts a new chain.
  3. Evaluates branches in order:
    • if branches first, then elseif branches.
    • The first branch whose condition is true becomes the chosen branch.
    • If none of the conditions are true, the else branch is chosen (when present).

The *else attribute itself never has its value evaluated; Sercrod only checks whether it is present. Any string given as its value is ignored and acts purely as documentation for humans.

Once a branch is chosen, Sercrod clones that element, strips *if, *elseif, *else, and *let / n-let from the clone, and renders that clone with the computed branch scope into the parent. Exactly one branch per chain is rendered.

Basic example

A simple access check with *if and *else:

<div *if="user && user.isAdmin">
  <p>Welcome, admin.</p>
</div>
<div *else>
  <p>Access denied.</p>
</div>

Behavior

Evaluation timing

Execution model

Variable creation

*else / n-else does not create any variables on its own.

Within a chain:

*else can therefore see variables defined by its own branch *let, but it does not introduce any special names like $switch or loop indices by itself.

Scope layering

For a typical chain:

No additional scope layering is introduced by *else itself; it simply participates in the same mechanism as the other branches.

Parent access

*else does not introduce any new parent-access semantics. Inside expressions used in the chosen branch (for example in *print or *if nested within the branch), access to:

works exactly as it does in any other element. The only responsibility of *else is to decide whether this branch is selected as the fallback.

Use with conditionals and loops

Best practices

Examples

Multiple chains in the same parent

Two independent chains controlled by different conditions:

<div *if="user">
  <p>Logged in as %user.name%.</p>
</div>
<div *else>
  <p>You are not logged in.</p>
</div>

<div *if="notifications.length > 0">
  <p>You have %notifications.length% notifications.</p>
</div>
<div *else>
  <p>No notifications.</p>
</div>
Using n-else with mixed prefixes

You can mix *if with n-else in the same chain:

<section *if="status === 'ok'">
  <p>All systems go.</p>
</section>
<section n-else>
  <p>Something is wrong.</p>
</section>

Notes