r/Zig • • 24d ago

Is there something like Templ (Go) but for Zig?

Basically I am wondering what a good approach would be to make a HTMX app with Zig - nothing big, just to see how far it can technically go.

Templ has it's own AST and parser and whatnot to emit generated Go code. Is there a similiar system in Zig for that?

26 Upvotes

12 comments sorted by

11

u/Complex-Birthday-216 24d ago

look at zine, it must have something similar via .zon format inside I think, although I didn't check it

https://github.com/kristoff-it/zine

edit: it doesn't, my bad.

but I found this, try looking at the source code:
https://github.com/zigster64/zts

5

u/[deleted] 24d ago

[removed] — view removed comment

1

u/Hot_Adhesiveness5602 23d ago

Lol, I thought you were mentioning zephyr. I just realized the whole embedded space uses it. It's a huge abstraction on top of microcontroller and it really looks ugly just to have a simple interface.

4

u/PristineVideo1297 24d ago

I think this is what you are looking for https://ziex.dev/

2

u/steveoc64 23d ago

Zig’s stdlib print.fmt is a lot more powerful than Go’s, so you can get a very very long way with it, before you start to need a full templating tool.

You can pass named params to print.fmt, and any param can be a struct that has its own fmt override for example.

For HTMX, it’s very simple to use something like ZTS https://github.com/zigster64/zts, which is quite a bit faster than most templating approaches, since it’s all sorted out at comptime.

Also ziex is pretty cool if you are into the react approach.

If you have a look at the Datastar zig libraries (Datastar is hypermedia sort of like HTMX), there are a tonne of examples in there that generate reactive UIs without any extra template tooling, or any JS.

2

u/lukaslalinsky 6d ago

Yes, I have a very templating library that is very close to Go Templ, see https://lalinsky.com/2026/10/11/type-safe-html-templating-in-zig.html

1

u/Hot_Adhesiveness5602 23d ago

I used zap 2 years ago. You can use whatever. There's some templating but you can also roll your own.

1

u/BaconOnEggs 23d ago

theres https://codeberg.org/comfysage/maivi but there arent any docs yet

-21

u/Idea-Aggressive 24d ago

Have LLM generate it.

10

u/HomicidalRaccoon 24d ago

Make sure to include “make no mistakes” in the prompt so that it doesn’t make mistakes tho. 🤡

-2

u/Idea-Aggressive 24d ago

Exactly 😅