Closed klnusbaum closed 1 year ago
There may be a different way to try to accomplish what I'm doing. Just curious as to how one might approach this.
There are several options for this:
Use index
in an if
block. This works on maps and can even dig deeper, but will "explode" if any intervening value isn’t indexable.
font_size {{ if index . "termFontSize" -}} {{ .termFontSize }} {{- else -}} 14.0 {{- end }}
Use index
with default
(from sprig):
font_size {{ index . "termFontSize" | default "14.0" }}
Use hasKey
(only works on known maps, from sprig):
font_size {{ if hasKey . "termFontSize" }}{{ .termFontSize }}{{- else -}}14.0{{- end }}
Use dig
(works on maps, but can dig deeper, from sprig):
font_size {{ dig "termFontSize" "14.0" . }}
font_size {{ dig "term" "fontSize" "14.0" . }} # showing the deeper, assuming [data.term] fontSize = "16.0"
Thanks, that did the trick!
I ended up going with:
font_size {{ index . "termFontSize" | default "14.0" }}
What exactly are you trying to do?
I have the following template for my
kitt.conf
The idea is that if a
~/.config/chezmoi/chezmoi.toml
exists and.termFontSize
is set, use that value. Otherwise, I'd like the font size to default to14.0
.What have you tried so far?
Trying to use the above template with no
~/.config/chezmoi/chezmoi.toml
file present results in the following error when I runchezmoi apply
I also tried reading https://www.chezmoi.io/user-guide/manage-machine-to-machine-differences/#use-templates but that doesn't seem to have any information on how to specify default values.
Where else have you checked for solutions?
Output of any commands you've tried with
--verbose
flagOutput of
chezmoi doctor