A developer with decades of web experience, from PHP 3.0 through Python, Perl, and Django templates, recently returned to web development using Zig. Building backends with zio and Dusty convinced them that arena allocators and Zig's comptime make web work practical, and htmx or Datastar allow SPAs without touching JavaScript or TypeScript.
What was missing was a templating system meeting four requirements: compile-time type safety, speed with no allocations and direct writes to std.Io.Writer, escaping of all inputs by default to prevent XSS, and syntax that still feels like writing HTML. No existing option satisfied all of them. Ziex, with its JSX-inspired approach, offered useful ideas, but it targets WASM, which did not suit the author's needs. Go's Templ then provided the clearest model.
The result is zt, a Zig adaptation of Templ. Templates are parsed and transpiled to Zig during zig build, so they can import app code and app code can import them. Parameters are fully typed, and rendering errors surface at compile time. The generated code simply writes to a std.Io.Writer, whether that is a socket or a buffer.
Usage is straightforward. Templates are declared with a templ keyword, can nest components through @children, and accept typed parameters such as optional user records. Rendering can be called directly or through Dusty's render helper for HTML responses.
Source: Hacker News · Summarized by HeadlinesBriefing