The following code panics at tmp.Execute
saying function "copyrightYear" not defined
import (
"os"
"html/template"
"fmt"
)
func main() {
fm := template.FuncMap{
"copyrightYear": func() string {
return fmt.Sprintf("%d", time.Now().Year())
},
}
tmp := template.Must(template.New("").Parse("{{copyrightYear}}")).Funcs(fm)
tmp.Execute(os.Stdout, nil)
}
What am I missing? I've poked around the documentation. Changing it to call copyrightYear
in the template, or copyrightYear .
doesn't fix it.