assigning "compiled" templates to a global variable
gpciceri opened this issue · 3 comments
if you "compile" a template (with ParseFile), its type is *mustache.template, that is not visible outside the package. I'd like to assign it to a (global) variable to complile once and use it everywhere in my program. So why not make it of a *mustache.Template type? I've tried a brutal name substitution in the mustache.go file, and it seems to work (sorry, I'm fairly new to both go and mustache.go). THX
How are you declaring the variable? When I declare templates I usually do it like this:
package main
import "mustache"
var tmpl, _ = mustache.ParseFile("filename")
func main() { ...}
You're right though, if you declare a template and refer to mustache.template, it'll give an error. There's no reason that template should be private.
I load the template in the main() (that is a web.go server stub) and pass it with the help a global variable to the funcion that handles the request. So if you can make the template public, the problem is resolved.
Just pushed a fix to make template public. Thanks for reporting this.