Description
When I use the embed static file in go1.16, I can not get the custom funcmap correctly in template.
engine := gin.New()
engine.SetFuncMap(myFuncMap)
t, _ := template.ParseFS(&embedFS, tmplPath)
engine.SetHTMLTemplate(t)
After SetFuncMap, I call template.ParseFS (&theEmbedFS, tempPath) to get the template, and finally set the template through SetHTMLTemplate, when I use the custom function in template, It will panic: function "myfunc" not defined, but When I use LoadHTMLGlob
from path, it works fine.
Environment
- go version: 1.16
- gin version (or commit ref): master
- operating system: macos
Comment From: bianzhifu
@axiaoxin use template.Funcs set myFuncMap
t, _ := template.Funcs(myFuncMap).ParseFS(&embedFS, tmplPath)
Comment From: threadtag
engine := gin.New()
// myFuncMap=template.FuncMap{"foo":bar}
t, _ := template.New("any").Funcs(myFuncMap).ParseFS(embedFS, tmplPath)
engine.SetHTMLTemplate(t)
this works for me