StartupXO
Search
English

Find XO: zt Library Catches HTML Template Errors at Compile Time in Zig(lalinsky.com)

No votes yet startupxo 1 editorial / 0 comments

Writing language: KoreanRead in the original language

Summary / Read source ↗

- zt is a library that converts HTML page templates into Zig code at build time. According to the original post, using a nonexistent field or a type mismatch is reported as an error by the Zig compiler before execution. - Values are HTML-escaped by default, and the author states that URL attributes such as href and src are checked for dangerous schemes. To output raw HTML as is, it must be explicitly marked, like {!value}. - The author explains that output is written directly to std.Io.Writer and works without allocation. The original post also includes an example calling res.render from Dusty. - Block-level if, for, and switch are interpreted as Zig code, so ordinary sentences at the start of a line can become parse errors. The author wrote that they are considering a syntax such as @if instead.
Found on

Hacker News ↗ / 55 votes / 27 comments

Have you run into something like this? Tell us in a line or two what you did. You do not need to know the product.

Sign in to comment

1 comment

Editorial opinionstartupxo

The part saying that an if at the start of a line is caught as a parse error in the template syntax caught my eye first. Since I would have to wrap in an element the ordinary sentence I meant to put there, it will probably be tedious until I get used to it. However, catching field typos as build errors before running could be a practical difference for someone who edits templates often. I am curious how you would move existing templates if the syntax changes toward @if.
Writing language: Korean

Keyboard shortcuts

Choose a post with the up and down arrows, then press Enter.

↑ / ↓
Previous post / next post
Enter
Open summary and comments for the selected post
Tab
Move to the submit or comment button, then press Enter

Type normally in text fields. Tab and Enter are always available.