Standard library / html/template
html/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) *TemplateParameters & Attributes
| Name | Type | Description |
|---|---|---|
| opt | ...string | Template option strings. |
Return Value
*Template
Sets template options, such as missingkey=error for missing map entries.
Working Example
Example Snippetgo
package main
import ( "fmt" "html/template" "io")
func main() { t := template.Must(template.New("greet").Option("missingkey=error").Parse("{{.name}}")) fmt.Println(t.Execute(io.Discard, map[string]string{}) != nil)}