{"id":14990809,"url":"https://github.com/ikskuh/ztt","last_synced_at":"2025-06-18T09:36:49.333Z","repository":{"id":68601351,"uuid":"336486969","full_name":"ikskuh/ZTT","owner":"ikskuh","description":"Precompiled Zig text template engine","archived":false,"fork":false,"pushed_at":"2023-05-22T06:22:31.000Z","size":13,"stargazers_count":32,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-05T05:21:55.221Z","etag":null,"topics":["template-engine","text-templating-engine","zig","zig-package","ziglang"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ikskuh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-02-06T08:04:04.000Z","updated_at":"2025-04-08T13:17:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"86ede435-f018-4e4d-800c-69b827f91539","html_url":"https://github.com/ikskuh/ZTT","commit_stats":null,"previous_names":["ikskuh/ztt"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ikskuh/ZTT","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikskuh%2FZTT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikskuh%2FZTT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikskuh%2FZTT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikskuh%2FZTT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ikskuh","download_url":"https://codeload.github.com/ikskuh/ZTT/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ikskuh%2FZTT/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260528478,"owners_count":23022950,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["template-engine","text-templating-engine","zig","zig-package","ziglang"],"created_at":"2024-09-24T14:20:53.463Z","updated_at":"2025-06-18T09:36:44.320Z","avatar_url":"https://github.com/ikskuh.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zig Text Templates\n\nThis project implements a template generator for Zig that works similar to how PHP works.\n\nIt allows you to mix plain text and Zig code to generate automatic text files.\n\nConsider the following example:\n\n```zig\n\u003c#\n// This tag let's you import global statements available to the `render()` function\nconst std = @import(\"std\");\n#\u003e\n\n# Zig Text Template\n\nThe following syntax inserts `ctx.intro` formattet with the format string `{s:-^10}`.\n\n\u003c= ctx.intro : {s:-^10} =\u003e\n\nThe list has the following \u003c= ctx.list.len =\u003e items:\n\n\u003c? for(ctx.list) |item| { ?\u003e\n    - \u003c= item.name : {s} =\u003e *(weight \u003c= item.weight : {d:.1} =\u003e kg)*\n\u003c? } ?\u003e\n\nYou can pass arbitrary format strings and expressions to the direct formatter:\n- \u003c= \"hello:world\" : {s} =\u003e\n- \u003c= (10 + 20 * 30) =\u003e\n- \u003c= std.math.log10(10 + 20 * 30) =\u003e\n\nNote that for using a `:` inside the format expression itself, use braces to encapsulate the items.\n\n```\n\nThis was inspired by both [PHP](https://www.php.net/manual/en/intro-whatis.php) and [Microsofts T4](https://docs.microsoft.com/en-us/visualstudio/modeling/code-generation-and-t4-text-templates?view=vs-2019) engine.\n\n## Usage\n\nEach generated template will yield a `zig` file which exports a function called `render`:\n```zig\npub fn render(stream: anytype, ctx: anytype) !void {\n  …\n}\n```\n\nThis function must be invoked with a `std.io.Writer` for the first argument and *any* value for the second argument. `ctx` is meant to pass information from the caller to the template engine to allow dynamic content generation.\n\nTo generate templates in your build script, just run the executable with `FileSource`s.\n\n```zig\n\u003c TO BE DONE \u003e\n```\n\nFor a full example, see `build.zig` and the `example` folder.\n\n## Syntax\n\nThe syntax knows these constructs:\n\n- `\u003c? … ?\u003e` will paste everything between the start and end sigil verbatim into the `render` function code. This can be used to generate loops, conditions, ...\n- `\u003c= expr =\u003e will print a default-formatted (`{}`) expression into the stream.\n- `\u003c= expr : format =\u003e` will behave similar to the default-formatted version, but you can specify your own format string in `format`. This accepts any format string that `std.fmt.format` accepts for the type of `expr`.\n- `\u003c# … #\u003e` will paste everything between the start and end sigil verbatim into the global scope of the Zig code. This can be used to create custom functions or exports.\n\nNote that both `\u003c# … #\u003e` and `\u003c? … ?\u003e` will swallow a directly following line break, while `\u003c= … =\u003e` will not. This makes writing templates more intuitive.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikskuh%2Fztt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fikskuh%2Fztt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fikskuh%2Fztt/lists"}