allowances/template.go
2013-02-20 21:11:44 -08:00

26 lines
473 B
Go

package main
import (
"html/template"
"path/filepath"
"sync"
)
var cachedTemplates = map[string]*template.Template{}
var cachedMutex sync.Mutex
func T(name string) *template.Template {
cachedMutex.Lock()
defer cachedMutex.Unlock()
if t, ok := cachedTemplates[name]; ok {
return t
}
t := template.New("_base.html")
t = template.Must(t.ParseFiles(
"templates/_base.html",
filepath.Join(*template_dir, name),
))
cachedTemplates[name] = t
return t
}