Closed arrrgi closed 1 year ago
$variable := value
in a new scope (e.g., your if
block) creates a new binding which is lost at the end of the scope. Use $variable = value
to reassign the value of the variable.
Thanks @halostatue , will give that a try now and report back
Looks good to me now, but not being overtly familiar with Go template/Sprig I wasn't able to easily spot this. Is there a good reference to the scoping consideration you mentioned @halostatue ??
Closed as resolved now.
Yes, in the Go text/template documentation. I know this from what programming in Go that I’ve done. I suspect that chezmoi could probably use a gentle introduction to Go templates in its documentation, as the Go documentation is fairly opaque, and even I have to refer to it periodically.
Maybe we could consider something similar to Hugo’s introduction to templating, as the basics largely overlap. This might be more of a chezmoi v3 thing since there is a desire to eliminate Sprig, so having one place to refer to chezmoi functions would be more sensible.
There is already https://chezmoi.io/user-guide/templating/. Improvements welcome.
Maybe we could consider something similar to Hugo’s introduction to templating, as the basics largely overlap. This might be more of a chezmoi v3 thing since there is a desire to eliminate Sprig, so having one place to refer to chezmoi functions would be more sensible.
Well that was a huge lightbulb moment for me, thanks for linking that as it makes much more sense now (sorry @twpayne !)
There is already https://chezmoi.io/user-guide/templating/. Improvements welcome.
When I have time, I may lift some stuff from Hugo’s documentation that’s not in the Chezmoi guide (what’s there is good, but doesn’t cover some of the basics like the Hugo one does).
What exactly are you trying to do?
In the following chezmoi.yaml.tmpl I have defined a number of empty variables, these should then be replaced by the values derived from prompts in the template when running
chezmoi init
orchezmoi init --data=false
but the init completes without error and my .data.git variables are empty, and the .boolEnvRestricted is still false even though I provided a 'true' input:What have you tried so far?
If I set the empty variables with default values, my inputs at prompts are also ignored and the defaults are applied to the .data.git variables
Where else have you checked for solutions?
Output of any commands you've tried with
--verbose
flag^^^no additional info sent to console, only the template prompts^^^
Output of
chezmoi doctor
Additional context
Add any other context about the problem here.