Templar is a fast, lightweight templating engine for directories and files, built with Go’s text/template and Sprig. It lets you define how directories are generated using simple, declarative control files, enabling dynamic, repeatable, and fully configurable project structures.
Templar is ideal for generating config files, scaffolding projects, or automating deployments — all with clean, composable templates.
- Directory-aware templating: Template entire directory trees, not just individual files.
- Control files (Tomes) define generation rules locally, per directory, (similar to a Makefile for templates).
- Tomes are templated themselves, as well as file- and directory names, allowing for dynamic output directroy structures.
- Filenames and paths are also templated, as well as symbolic-link names and their targets
- Go templates + Sprig functions: Powerful templating features out of the box.
Download a prebuilt binary from the Releases.
-
Clone the repository:
git clone https://github.com/romosch/templar.git cd templar -
Build the binary:
go build -o templar
templar [options] <input dir/file>-c,--copyGlob pattern for files to copy without templating (can be repeated)-d,--dry-runSimulate actions without writing files-e,--excludeGlob pattern of files to exclude (can be repeated)-F,--forceOverwrite files in output directory without confirmation-h,--helpShow help and exit-i,--includeGlob pattern of files to include (can be repeated)-m,--modeSet file mode (permissions) for created files (octal or symbolic)-o,--outOutput directory for generated files (default: standard output)-s,--sSet a value (key=value) (can be repeated)-S,--strictFail on missing values-r,--stripSuffix to strip from output filenames if templated (can be repeated)-t,--tempGlob pattern for files to template; others are copied as-is (mutually exclusive with--copy)-v,--valuesPath to values YAML file (can be repeated)-D,--verboseEnable verbose logging-V,--versionShow version and exit
A Tome is a special YAML file (.tome.yaml) placed inside any template directory.
It acts as a blueprint for rendering, telling Templar how the contents of that directory should be processed and where the generated outputs should be written.
Tomes enable local control and dynamic generation. A single template directory can produce one, many, or differently customized outputs, all from the same source.
Tome files themselves are templates. Before being evaluated, a .tome.yaml is rendered just like any other file — allowing using input variables, conditional logic, and Sprig functions to control how the directory behaves based on the provided values.
A .tome.yaml file can be composed of a single tome, or a list of them, each with the following properties:
| Property | Type | Description | Default |
|---|---|---|---|
mode |
string |
Octal/symbolic file-mode specifying rendered files type and permissions | Same as template |
target |
string |
Target directory (relative or absolute) | Same as template |
strip |
string |
Suffix to strip from output filenames | None |
include |
[]string |
Glob patterns of files to include (can be repeated) | All |
exclude |
[]string |
Glob patterns of files to exclude (can be repeated) | None |
copy |
[]string |
Glob patterns for files to copy without templating (can be repeated) | None |
temp |
[]string |
Glob patterns for files to template; others copied | All |
values |
map[string] |
Key-value map containing the (default) values for rendering. Overwritten by higher-level values | None |
Templar uses Go's text/template extended with functions from sprig and the following custom functions:
Returns a slice Overrides the sprig seq function to return a slice instead of a string.
Imports the content from another file. The imported content is templated using the same values as for the current file.
Converts a given list, slice, array, dict, or object to YAML string.
Converts a YAML string to an iterable map object.
Converts a list, slice, array, dict, or object to JSON string.
Converts a JSON string to an iterable map object.
Converts a list, slice, array, dict, or object to TOML string.
Converts a TOML string to an iterable map object.
Throws an error if passed variable is undefined
Contributions are welcome! Please open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
