Not without implementing your own function to do it, I've been using something like this
(并非没有实现自己的功能才能做到这一点,我一直在使用这样的东西)
func ParseTemplates() *template.Template {
templ := template.New("")
err := filepath.Walk("./views", func(path string, info os.FileInfo, err error) error {
if strings.Contains(path, ".html") {
_, err = templ.ParseFiles(path)
if err != nil {
log.Println(err)
}
}
return err
})
if err != nil {
panic(err)
}
return templ
}
This will parse all your templates then you can render them by calling their names eg
(这将解析所有模板,然后您可以通过调用它们的名称来渲染它们,例如)
template.ExecuteTemplate(w, "home", nil)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…