Standard library / text/template

text/template.Template.Option()

Sets template options, such as missingkey=error for missing map entries. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func (t *Template) Option(opt ...string) *Template

Parameters & Attributes

NameTypeDescription
opt...stringTemplate option strings.

Return Value

*Template

Sets template options, such as missingkey=error for missing map entries.

Working Example

Example Snippetgo
package main
import (  "fmt"  "io"  "text/template")
func main() {  t := template.Must(template.New("greet").Option("missingkey=error").Parse("{{.name}}"))  fmt.Println(t.Execute(io.Discard, map[string]string{}) != nil)}
Go Reference