I have declared a global var as suggested in this question Is it necessary to put templates into a map for reusing in Go?
I declared the global var in my main package before func main()
but it is still not declared in another package.
package main
import{
"html/template"
.....
)
var tmpl = template.New("master")
func main() {
func init() {
_, err := tmpl.ParseGlob("templates/*.html")
if err != nil {
log.Fatalln("Error loading templates:", err)
}
....
}
In another package I write inside a function:
tmpl.ExecuteTemplate(w, "venue-index.html", res)
but I get an error
tmpl: undefined
I realise that there are other similar questions but the answers have not solved my problem. What am I doing wrong?