Basics · Signals
Text vs attributes
Signals read differently in two places.
In template text, a bare signal name auto-unwraps: {count} compiles
to count.Get(). You never write .Get() yourself there — {count.Get()}
would become count.Get().Get() and fail to compile.
In an attribute expression — class={…} — the opposite holds. The
value is raw Go, emitted unchanged, so a signal there needs an explicit
.Get(). The compiler owns template text and unwraps it; an attribute is
code you wrote, left as-is.
This counter shows its value in text (auto-unwrapped). We want the box to turn red once the count reaches the goal, which means a class driven by the signal.
Your turn
Give the box a dynamic class. Add a boxClass function that reads the
signal with .Get():
func boxClass() string {
if count.Get() >= goal {
return "box full"
}
return "box"
}
Then change the box’s class="box" to class={boxClass()}. Press Run
and count up to five — the border turns red. Solve shows the finished
version; Reset restores the start.