A new Zig templating tool called zt adapts ideas from JSX-like and Go templating systems to provide type-safe, allocation-free HTML generation. Templates are parsed at build time and transpiled to Zig code that writes directly to a std.Io.Writer, so rendering can target sockets or buffers without intermediate allocations. All template parameters are regular Zig types because templates can import application code, making mismatched types and missing fields compile-time errors. Dynamic values are HTML-escaped by default, URL attributes are checked for dangerous schemes, and raw HTML requires an explicit marker. The parser enforces properly closed elements and the generated code includes comments that map compiler errors back to template locations.
Control flow in templates uses ordinary Zig constructs (if, for, switch), reusable components and @children support layout composition, and everything compiles down to a sequence of writes with no runtime allocations. One syntactic edge case is that block-level Zig keywords can make plain text like “if you forgot…” a parse error; the author is considering switching to @if/@for/@switch to remove ambiguity. The project is already in use by multiple people but remains early-stage; feedback and issues are invited on GitHub or Zig community channels.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.