I have multiple template files (base.html, header.html, footer.html, content.html, etc.) that I pass to ParseFiles and it works as expected. Bring in Funcs however and I have never been able to successfully call my funcs from the templates when using ParseFiles:
t, _ := template.New(noNameWorks).Funcs(f).ParseFiles("a.html", "b.html", "c.html")
I've tried various names - "a.html", "b.html", "c.html","a", "b", "c", (special mention: "mercy", "@F#$%*") - but it always errors out complaining about my func being not defined.
So then I resorted to reading the files myself and calling Parse and that works:
t := template.New("LiterallyAnyNameWorks").Funcs(f)
for _, tmpl := range[]string{"a.html","b.html","c.html"} {
b, _ := ioutil.ReadFile(tmpl)
t, _ = t.Parse(string(b))
}
What name can I give to my template to get ParseFiles to work and also what's the significance of giving a name to the template?
Thanks,
Keyur