From Lukáš Lalinský · Lukáš Lalinský · · 1m 50s
Type-safe HTML templating in Zig
Zig developer creates type-safe HTML templating library for web apps.
In brief
Zig developer creates type-safe HTML templating library for web apps. Zig developer built zt, a type-safe HTML templating library that compiles templates to Zig code for secure web development without JavaScript. Originally reported by Lukáš Lalinský.
Web development history
Lukáš Lalinský started web development in 2000 after PHP 3.0 release and used multiple approaches including PHP, Python, and Perl templates before moving to JavaScript frameworks.
Zig adoption for web
Two years ago, Lalinský began using Zig for API backends with zio and Dusty, realizing web development is manageable with arena allocators and comptime.
Template requirements
Lalinský needed a type-safe, fast, safe default escaping, and html-friendly templating library that didn’t require javascript.
Ziex and Templ inspiration
Lalinský discovered Ziex for zig and Templ for go, using their approaches to build zt with type-safe html rendering.
zt template syntax
zt templates parse to zig code, import app code, and use type-safe rendering with html escaping by default.
Template example
The HomePage template renders user data with html escaping and conditional logic using zig’s if statements.
Error handling
Zig compiler catches template errors like missing fields, preventing runtime template errors and xss vulnerabilities.
Dusty integration
zt works with Dusty to render html pages directly from zig code without javascript.
XSS protection
All inputs are html-escaped by default, with dangerous schemes checked in url attributes to prevent xss.
Template features
zt supports reusable components, layout inheritance via @children, and control flow with zig’s if/for/switch statements.
Open issue
Block-level control flow in templates is ambiguous, with potential for cleaner syntax using @if/@for/@switch.
Community feedback
Lalinský welcomes feedback and issues for zt, which is still early but used by multiple developers.
The essence
Zig developer built zt, a type-safe HTML templating library that compiles templates to Zig code for secure web development without JavaScript.





