Standard library / html/template
html/template.Template.Funcs()
Registers named functions before parsing. A function can return one value or a value and error. Expected stdout: 'ADA\n'.
Formal Syntax & Structure
go syntaxgo
func (t *Template) Funcs(funcMap FuncMap) *TemplateParameters & Attributes
| Name | Type | Description |
|---|---|---|
| funcMap | FuncMap | Named functions available to template actions. |
Return Value
*Template
Registers named functions before parsing.
Working Example
Example Snippetgo
package main
import ( "fmt" "html/template" "os" "strings")
func check(e error) { if e != nil { panic(e) }}
func main() { t := template.Must(template.New("greet").Funcs(template.FuncMap{"upper": strings.ToUpper}).Parse("{{upper .}}")) check(t.Execute(os.Stdout, "Ada")) fmt.Println()}