tmplx
Write Go in HTML
A page is one HTML file with a Go script block. State is a var, handlers are Go statements in attributes, and every handler runs on the server. tmplx compiles it all into a single routes.go on net/http — there is no JavaScript to write.
A query in your HTML
Type below. Every keystroke posts the state up, runs albums.Search(q) on the server, and morphs the rows that come back. results is derived from q, so it recomputes whenever q changes.
| Kind of Blue | Miles Davis | 1959 |
| A Love Supreme | John Coltrane | 1965 |
| Abbey Road | The Beatles | 1969 |
| The Dark Side of the Moon | Pink Floyd | 1973 |
| Rumours | Fleetwood Mac | 1977 |
| Thriller | Michael Jackson | 1982 |
| Purple Rain | Prince | 1984 |
| Nevermind | Nirvana | 1991 |
| OK Computer | Radiohead | 1997 |
| Discovery | Daft Punk | 2001 |
albums.Search is an ordinary Go function in an ordinary Go package — an in-memory table here, your real database in production.
The tmplx way
- State is a var. Declare it in the script block, render it with
{ }. When a handler changes it, every place that reads it updates. - Handlers are server code.
tx-onclick="counter++"is Go, not JavaScript. Call anything in your module — no fetch, no API routes, no JSON layer. - The server stays stateless. State travels with the page: each event sends it up, HTML comes back down, and the DOM morphs in place.
- Components are HTML files.
components/card.htmlbecomes<tx-card>, with props, slots, and callbacks.
Demos
Counter
State, rendered and mutated, in five lines.
0
To Do
A form posts straight to a Go function; click an item to remove it.
From file to server
- Install the compiler:
go install github.com/gnituy18/tmplx@latest - Write pages in
pages/and components incomponents/. - Run
tmplx— it type-checks every file and generatesroutes.go. Thengo run .