Closed triallax closed 3 years ago
When a template gets executed with {{ template "name" }}
, it will be executed with nil
data unless you explicitly provide some other value. (See here in the docs for Go's text/template
feature for more details).
You should be able to fix it by explicitly passing .
in instead:
{{- template "file.toml" . }}
I haven't actually tested this myself because when I tried I got some very weird errors trying to add a new template in .chezmoitemplates
. (I'll file a separate issue about that if I can't track it down). But I'm pretty sure it'll work 😄
Thanks for the help! I'm away from the machine with the error right now, so I'll be keeping this open till I confirm that everything works. I was following https://www.chezmoi.io/docs/how-to/#handle-different-file-locations-on-different-systems-with-the-same-contents, which does not include the explicit passing of .
you noted. Maybe I'll open a PR to update that part.
@zb140 that seems to have done the trick. Thanks again!
What exactly are you trying to do?
Trying to write a template for a configuration file which has different locations on different systems. I have a file in
.chezmoitemplates
; let's call itfile.toml
. Here are the file's contents (I've removed all unnecessary details):I then have the actual config file with the following content:
The issue is that
{{ chezmoi.homeDir }}
doesn't work, giving me the following error:What have you tried so far?
Running
chezmoi execute-template "{{ .chezmoi.homeDir }}"
works just fine.Where else have you checked for solutions?
Output of any commands you've tried with
--verbose
Output of
chezmoi doctor
Additional context
None.