Golang html/template.Template.Funcs function example
package html/template
Funcs adds the elements of the argument map to the template's function map. It panics if a value in the map is not a function with appropriate return type. However, it is legal to overwrite elements of the map. The return value is the template, so calls can be chained.
Golang html/template.Template.Funcs function usage example
tmpl := template.New(path.Base(files[0])).Funcs(template.FuncMap{
"asset": server.templateAsset,
"dump": templateDumpMap,
"eq": templateEqual,
"ne": templateNotEqual,
"substr": templateSubstr,
})
// Execute template
tmpl, err = tmpl.ParseFiles(files...)
if err != nil {
return err
}
tmplData := bytes.NewBuffer(nil)
err = tmpl.Execute(tmplData, data)
if err != nil {
return err
}
...
References :
https://github.com/facette/facette/blob/master/pkg/server/template.go
Advertisement
Something interesting
Tutorials
+23.6k Golang : minus time with Time.Add() or Time.AddDate() functions to calculate past date
+9.9k Golang : Turn string or text file into slice example
+13.2k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+21.8k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+10.3k Golang : Convert file unix timestamp to UTC time example
+9.4k Golang : Terminate-stay-resident or daemonize your program?
+37.7k Golang : Comparing date or timestamp
+20.2k Golang : How to get own program name during runtime ?
+5.8k Golang : Find change in a combination of coins example
+11.1k Golang : Roll the dice example