If/else
templ uses standard Go if
/else
statements which can be used to conditionally render components and elements.
component.templ
templ login(isLoggedIn bool) {
if isLoggedIn {
<div>Welcome back!</div>
} else {
<input name="login" type="button" value="Log in"/>
}
}
main.go
package main
import (
"context"
"os"
)
func main() {
login(true).Render(context.Background(), os.Stdout)
}
Output
<div>
Welcome back!
</div>