Skip template if a referenced variable is missing? #4388
-
As stated, I am trying to create a template file that references a few user-defined variables. But when any one of these necessary variables are unset, I wish for chezmoi to skip the file (and perhaps emit a warning) instead of hard-erroring. Is this something chezmoi supports? If not please treat this as a feature request. P.s. I'm not terribly familiar with go templating, so maybe there is already a built-in way to do this that I'm not aware of. Anyways, please enlighten me. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
You can use the
Alternatively, you can set this globally by setting [template]
options = ["missing-key=zero"] |
Beta Was this translation helpful? Give feedback.
Right. The mode you want won't work because this is a feature of go templating. However, you can do this (a) without
missing-key=zero
and (b) without this feature:Unless you have the
empty_
attribute set (foo.conf.d/empty_enable-feature-a.conf.tmpl
), chezmoi will not create files that evaluate to empty contents, but they have to be completely empty (no whitespace or anything).If there are multiple values to possibly check, you can easily do this with
if or $a $b $c $d $e…
; if all of them must be true, thenif …