Newb trying to get output-map working with external template #1676
-
I was following the documentation here to learn how to use out.t {{- /* .in may contain a directory name - we want to preserve that */ -}}
{{ $f := filepath.Base .in -}}
out/{{ .in | strings.ReplaceAll $f (index .filemap $f) }}.out as well as the filemap.json file: filemap.json { "eins.txt": "uno", "deux.txt": "dos" } and stored my templates in the gomplate -t out=out.t -c filemap.json --input-dir=in --output-map='{{ template "out" }}' I get the following error: ERR error="failed to gather templates for rendering: failed to render outputMap with ctx &map[ctx:0xc000a4e1b0 filemap:map[deux.txt:dos eins.txt:uno] in:deux.txt] and inPath deux.txt: failed to render template <OutputMap>: template: out:2:7: executing \"out\" at <.in>: nil data; no entry for key \"in\"" I am sure that I have a basic misunderstanding. Can someone please help point me in the right direction? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @dgarlitt, thanks for reporting this - it looks like this is at least a bug in the documentation, and likely also a bug with how nested templates interact with output maps. I tested this with various gomplate versions all the way back to v3.4.0 (when the output-map feature was added), and I get the same error too. |
Beta Was this translation helpful? Give feedback.
-
Many thanks to @thesuperzapper, who pointed out that the doc bug is that the context ( So, the correct command is: gomplate -t out=out.t -c filemap.json --input-dir=in --output-map='{{ template "out" . }}' The docs are fixed in #1745 |
Beta Was this translation helpful? Give feedback.
Many thanks to @thesuperzapper, who pointed out that the doc bug is that the context (
.
) needs to be passed to thetemplate
function for the example to work:So, the correct command is:
gomplate -t out=out.t -c filemap.json --input-dir=in --output-map='{{ template "out" . }}'
The docs are fixed in #1745