Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

output-map not working with external template #1686

Closed
hairyhenderson opened this issue Mar 24, 2023 Discussed in #1676 · 3 comments · Fixed by #1745
Closed

output-map not working with external template #1686

hairyhenderson opened this issue Mar 24, 2023 Discussed in #1676 · 3 comments · Fixed by #1745
Assignees
Labels

Comments

@hairyhenderson
Copy link
Owner

Discussed in #1676

Originally posted by dgarlitt March 15, 2023
I was following the documentation here to learn how to use --output-map with external templates. I created the out.t file as indicated:

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 in directory. However, when I run the command in the example:

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?

@hairyhenderson
Copy link
Owner Author

My response:

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.

@hairyhenderson hairyhenderson self-assigned this Mar 24, 2023
@thesuperzapper
Copy link

@hairyhenderson are you sure you did not just forget to provide the context to the template, that is:

  • GOOD: --output-map='{{ template "out" . }}'
  • BAD: --output-map='{{ template "out" }}'

@hairyhenderson
Copy link
Owner Author

😂 thanks so much @thesuperzapper - that's the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants