Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Commit 87a2a0b

Browse files
committed
Use missingkey=zero rather than error in template rendering.
When performing complex template rendering, it is helpful to be able to perform if statements based on the existence of a passed variable like `if .env`. The template runs fine if the variable is passed, but if it isn't the execution will stop because of the missingkey setting. This change proposes setting the missingkey value to zero rather than error. This means that rather than error out, the operation returns the zero value for the map type's element and the render execution can continue.
1 parent 890ebbf commit 87a2a0b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

template/template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const (
2828
func (t *tmpl) newTemplate() *template.Template {
2929
tmpl := template.New("jobTemplate")
3030
tmpl.Delims(leftDelim, rightDelim)
31-
tmpl.Option("missingkey=error")
31+
tmpl.Option("missingkey=zero")
3232
tmpl.Funcs(funcMap(t.consulClient))
3333
return tmpl
3434
}

0 commit comments

Comments
 (0)