Ever wanted to use Go's text/template in shell tooling instead of having to use a here document? Well, now you can. templater is a command line tool that accepts an arbitrary template input file, and a JSON data file to use as the context for rendering the template.
Now you can drive templates that use inline conditionals, loops, format strings from the convenience of any script that allows you to fork out to templater.
This tool is an open source project of LiveRamp. Want to hack on cool Go projects at adtech scale? Come work for us!
$ go get -u github.com/LiveRamp/templater
$ go install github.com/LiveRamp/templater
Usage of templater:
-data string
Data file to use as template context
-template string
Template to render
Example template input file:
I have three students:
{{ range $index, $element := .Students }}
One student is named {{ $element }}.
{{ end }}
Example JSON data file:
{"Students": ["Curly", "Larry", "Moe"]}
Rendering the template:
$ templater -template example.tmpl -data example.json
I have three students:
One student is named Curly.
One student is named Larry.
One student is named Moe.
- Load multiple templates into the context so you can include other templates from the root template.
- Multiple data files with precedence.
- Additional template context functions defined in Go to reach parity with Erubis, Jinja, etc.