Select a branch from state
A conditional block creates the branch selected by its condition. Read the signal explicitly in that condition.
<script>let shown: Signal<bool> = Signal::new(true);</script><style>:global(body) { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 16px; }</style><input type="checkbox" bind:checked={shown} />{if shown.get()} <p>The details are visible.</p>{else} <p>The details are hidden.</p>{/if} The checkbox binding changes shown. When the condition changes value, the block removes the old branch and builds the new one before its anchor node.
Removed content is disposed
Each branch has an owner. Removing a branch disposes that owner and stops its reactive effects. This is a tree change, not just a visibility change applied to content that stays mounted.
A nested block belongs to its enclosing branch. Removing the branch also removes that nested block’s current nodes.
Use a nested condition for another case
The compiler supports an optional else branch. It does not support an else-if form at this revision. Put another conditional inside the else branch when another decision is needed.
A condition containing a signal must read the signal, as shown.get() does here. The shorthand used for a bare signal in a text hole does not apply to conditions.
When shown becomes false, does the first paragraph stay in the tree?
No. Its branch is removed and its owner is disposed. The else branch supplies the paragraph that replaces it.
Try both branches
Save this over crates/demos/demos/hello.wisp and run cargo run -p vapors-app --example demo -- hello. Click the checkbox, then use Tab to focus it and Space to toggle it. The paragraph should switch between the two branches.
Change the initial value to false and rebuild. The hidden-details branch should now appear first. The checkbox demo provides a hosted example of checkbox bindings.