Zmpl is a templating language for Zig 🦎
- Use Zig code directly in templates for control flow.
- Simple and intuitive DSL for building flexible, JSON-compatible data objects.
- Compiles to Zig code for syntax and type validation.
- Used by the Jetzig web framework.
# src/templates/example.zmpl
if (std.mem.eql(u8, "zmpl is simple", "zmpl" ++ " is " ++ "simple")) {
<div>Email: {.user.email}</div>
<div>Token: {.auth.token}</div>
}
const zmpl = @import("zmpl");
const manifest = @import("templates/zmpl.manifest.zig"); // Auto-generated by Zmpl.
test "readme example" {
var data = zmpl.Data.init(allocator);
defer data.deinit();
var body = try data.object();
var user = try data.object();
var auth = try data.object();
try user.put("email", data.string("user@example.com"));
try auth.put("token", data.string("abc123-456-def"));
try body.put("user", user.*);
try body.put("auth", auth.*);
const output = try manifest.templates.example.render(&data);
defer allocator.free(output);
try std.testing.expectEqualStrings(
\\ <div>Email: user@example.com</div>
\\ <div>Token: abc123-456-def</div>
\\
, output);
}
Templ - inspiration for template layout.