Skip to content

Zmpl is a templating language written in Zig

License

Notifications You must be signed in to change notification settings

stephenafamo/zmpl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zmpl

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);
}

License

MIT

Credits

Templ - inspiration for template layout.

About

Zmpl is a templating language written in Zig

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Zig 98.2%
  • Zimpl 1.8%