{"id":19614276,"url":"https://github.com/jimmysawczuk/tmpl","last_synced_at":"2026-06-13T00:32:39.406Z","repository":{"id":32979432,"uuid":"119127206","full_name":"jimmysawczuk/tmpl","owner":"jimmysawczuk","description":"Lightweight Go template executor","archived":false,"fork":false,"pushed_at":"2025-08-24T00:25:13.000Z","size":1487,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-20T13:51:32.025Z","etag":null,"topics":["go","templates","tool"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jimmysawczuk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-27T03:03:24.000Z","updated_at":"2025-08-24T00:24:58.000Z","dependencies_parsed_at":"2022-08-07T19:16:37.367Z","dependency_job_id":null,"html_url":"https://github.com/jimmysawczuk/tmpl","commit_stats":null,"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"purl":"pkg:github/jimmysawczuk/tmpl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmysawczuk%2Ftmpl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmysawczuk%2Ftmpl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmysawczuk%2Ftmpl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmysawczuk%2Ftmpl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jimmysawczuk","download_url":"https://codeload.github.com/jimmysawczuk/tmpl/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimmysawczuk%2Ftmpl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34268187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-12T02:00:06.859Z","response_time":109,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["go","templates","tool"],"created_at":"2024-11-11T10:50:31.243Z","updated_at":"2026-06-13T00:32:39.385Z","avatar_url":"https://github.com/jimmysawczuk.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tmpl\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/jimmysawczuk/tmpl)](https://goreportcard.com/report/github.com/jimmysawczuk/tmpl)\n\n**tmpl** is a small command-line utility to execute Go templates (defined in [`text/template`](https://golang.org/pkg/text/template) and [`html/template`](https://golang.org/pkg/html/template)) on files.\n\n## Features\n\nBy default, tmpl processes configuration from a file named `tmpl.config.json` in the working directory. You can override this file path with the `-f` flag.\n\nHere's a sample configuration file:\n\n```jsonc\n[\n\t{\n\t\t\"in\": \"index.tmpl\",\n\t\t\"out\": \"out/index.html\",\n\t\t\"format\": \"html\", // Can be \"html\", \"json\", or \"\".\n\t\t\"options\": {\n\t\t\t// Whether or not to minify the output (default: false; has no effect\n\t\t\t// when the format is \"\")\n\t\t\t\"minify\": true,\n\n\t\t\t// Environment variables to pass in for use in the template. You can\n\t\t\t// also set environment variables normally; variables set in the config\n\t\t\t// file take precedence.\n\t\t\t\"env\": {\n\t\t\t\t\"FOO\": \"BAR\"\n\t\t\t}\n\t\t}\n\t}\n]\n```\n\n## Functions\n\nIn addition to the [built-in functions](https://pkg.go.dev/text/template#hdr-Functions) provided by the `text/template` package, these functions are available in every template:\n\n-   [`add`](#add)\n-   [`asset`](#asset)\n-   [`autoreload`](#autoreload)\n-   [`env`](#env)\n-   [`file`](#file)\n-   [`formatTime`](#formatTime)\n-   [`getJSON`](#getJSON)\n-   [`inline`](#inline)\n-   [`jsonify`](#jsonify)\n-   [`markdown`](#markdown)\n-   [`now`](#now)\n-   [`parseTime`](#parseTime)\n-   [`ref`](#ref)\n-   [`safeCSS`](#safeCSS)\n-   [`safeHTML`](#safeHTML)\n-   [`safeHTMLAttr`](#safeHTMLAttr)\n-   [`safeJS`](#safeJS)\n-   [`seq`](#seq)\n-   [`sub`](#sub)\n-   [`svg`](#svg)\n-   [`timeIn`](#timeIn)\n\n### `add`\n\n\u003e add returns the sum of the two arguments.\n\n```\n{{ add 2 2 }}\n```\n\nreturns\n\n```\n4\n```\n\n### `asset`\n\n\u003e asset returns the path provided. In the future, asset may gain the ability to clean or validate the path.\n\n```\n{{ asset \"/css/style.css\" }}\n```\n\nreturns\n\n```\n/css/style.css\n```\n\n### `autoreload`\n\n\u003e autoreload returns an HTML snippet that you can embed in your templates to automatically reload the page when a change is detected.\n\n```\n{{ autoreload }}\n```\n\nreturns\n\n```\n\u003cscript\u003e...\u003c/script\u003e\n```\n\n### `env`\n\n\u003e env returns the environment variable defined at the provided key. Variables set in `tmpl.config.json` take precedence.\n\n```\n{{ env \"NODE_ENV\" }}\n```\n\nreturns\n\n```\nproduction\n```\n\n### `file`\n\n\u003e file loads the file at the path provided and returns its contents. It _does not_ create a ref; updating this file's contents won't trigger an update in watch mode.\n\n```\n{{ file \"some-letter.txt\" }}\n```\n\nreturns\n\n```\n...data...\n```\n\n### `formatTime`\n\n\u003e formatTime formats the provided time with the provided format. You can either specify both arguments at once or pipe a `time.Time` into this function to format it.\n\n```\n{{ now | formatTime \"Jan 2, 2006 3:04 PM\" }}\n{{ formatTime now \"Jan 2, 2006 3:04 PM\" }}\n```\n\nreturns\n\n```\nNov 28, 2021 10:09 AM\nNov 28, 2021 10:09 AM\n```\n\n### `getJSON`\n\n\u003e getJSON loads the file at the provided path and unmarshals it into a `map[string]interface{}`. It _does not_ create a ref; updating this file's contents won't trigger an update in watch mode.\n\n```\n{{ getJSON \"REVISION.json\" }}\n```\n\nreturns\n\n```\nmap[string]interface{}{\n    ...\n}\n```\n\n### `inline`\n\n\u003e inline loads the file at the path provided and returns its contents. It creates a ref so that updates to the file trigger an update in watch mode.\n\n```\n{{ file \"some-letter.txt\" }}\n```\n\nreturns\n\n```\n...data...\n```\n\n### `jsonify`\n\n\u003e jsonify marshals the provided input as a JSON string.\n\n```\n{{ now | jsonify }}\n```\n\nreturns\n\n```\n\"2021-11-28T10:09:00Z\"\n```\n\n### `markdown`\n\n\u003e markdown reads the file at the provided path, parses its contents as Markdown and returns the HTML. It creates a ref so that updates to the file trigger an update in watch mode.\n\n```\n{{ markdown \"path-to-markdown.md\" }}\n```\n\nreturns\n\n```\n\u003ch1\u003e...\u003c/h1\u003e\n\n\u003cp\u003e...\u003c/p\u003e\n```\n\n### `now`\n\n\u003e now returns the time of the template's execution in the local timezone.\n\n```\n{{ now | jsonify }}\n```\n\nreturns\n\n```\n\"2021-11-28T10:09:00Z\"\n```\n\n### `parseTime`\n\n\u003e parseTime returns a `time.Time` from the provided string in RFC3339 format.\n\n```\n{{ parseTime \"2021-11-28T10:09:00Z\" }}\n```\n\nreturns\n\n```\na time.Time\n```\n\n### `ref`\n\n\u003e ref creates a ref to the provided path so that an automatic update is triggered when the file at that path is changed. ref produces no output.\n\n```\n{{ ref \"public/style.css\" }}\n```\n\nreturns\n\n```\n\n```\n\n### `safeCSS`\n\n### `safeHTML`\n\n### `safeHTMLAttr`\n\n### `safeJS`\n\n\u003e The `safe*` functions mark their inputs as \"safe\" so they're not further escaped. See the documentation for [CSS](https://pkg.go.dev/html/template#CSS), [HTML](https://pkg.go.dev/html/template#HTML), [HTMLAttr](https://pkg.go.dev/html/template#HTMLAttr), and [JS](https://pkg.go.dev/html/template#JS) in `html/template`.\n\n### `seq`\n\n\u003e seq returns a slice of `n` elements. Useful for `range`.\n\n```\n{{ seq 5 }}\n{{ range seq 3 }}\nHello!\n{{ end }}\n```\n\nreturns\n\n```\n[0, 1, 2, 3, 4]\nHello!\nHello!\nHello!\n```\n\n### `sub`\n\n\u003e sub returns the difference between the two arguments.\n\n```\n{{ sub 3 2 }}\n```\n\nreturns\n\n```\n1\n```\n\n### `svg`\n\n\u003e svg reads the file at the provided path and returns its contents. It creates a ref so that updates to the file trigger an update in watch mode.\n\n```\n{{ svg \"path-to-svg.svg\" }}\n```\n\nreturns\n\n```\n\u003csvg\u003e...\u003c/svg\u003e\n```\n\n### `timeIn`\n\n\u003e timeIn returns the provided time in the provided timezone.\n\n```\n{{ now | timeIn \"America/Los_Angeles\" | jsonify }}\n```\n\nreturns\n\n```\n\"2021-11-28T02:09:00-0800\"\n```\n\n---\n\n## Watch mode\n\nWatch mode (`-w`) watches all of the templates in your config for changes and rebuilds them when they're changed. Additionally, any files referenced in your templates via `ref` or similar template functions will trigger a rebuild of the template.\n\n## Server mode\n\nServer mode (`-s`) is the same as watch mode except it also spins up a webserver that will serve the base directory.\n\nAdditionally, this webserver has an endpoint (`/__tmpl`) which will resolve when a change is made. You can use the `autoreload` function in your template to automatically reload the page when this endpoint resolves.\n\n## Subcommand\n\nYou can pass in a subcommand to be run by providing the `--` flag and then your command. You might want to use this if you need to run a second development process, like webpack, alongside your templates.\n\nHere's an example:\n\n```sh\n$ tmpl -w -- webpack -w --mode=development\n```\n\n## License\n\n[MIT](/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimmysawczuk%2Ftmpl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimmysawczuk%2Ftmpl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimmysawczuk%2Ftmpl/lists"}