Back to articles
Templ Has a Free API — Type-Safe HTML Templates for Go

Templ Has a Free API — Type-Safe HTML Templates for Go

via Dev.to WebdevAlex Spinov

Templ is a Go templating language that generates type-safe Go code from HTML templates. No more html/template string parsing — get compile-time errors for template bugs. Why Templ? Type-safe — template errors caught at compile time, not runtime Go code — templates compile to Go functions LSP support — autocomplete, go-to-definition in templates HTMX-friendly — perfect companion for HTMX + Go stacks Quick Start go install github.com/a-h/templ/cmd/templ@latest // hello.templ package main templ Hello ( name string ) { < div > < h1 > Hello , { name } !</ h1 > < p > Welcome to Templ .</ p > </ div > } templ generate // main.go package main import ( "net/http" "github.com/a-h/templ" ) func main () { http . Handle ( "/" , templ . Handler ( Hello ( "World" ))) http . ListenAndServe ( ":3000" , nil ) } Components with Props // components.templ package components type User struct { Name string Email string Admin bool } templ UserCard ( user User ) { < div class = "card" > < h3 > { user . Name }

Continue reading on Dev.to Webdev

Opens in a new tab

Read Full Article
2 views

Related Articles