package router
import (
"html/template"
"path/filepath"
)
var TemplateDir = "templates"
var homeTemplate, searchTemplate, faqTemplate, uploadTemplate, viewTemplate, viewRegisterTemplate, viewLoginTemplate, viewRegisterSuccessTemplate *template.Template
type templateLoader struct {
templ **template.Template
file string
name string
}
// ReloadTemplates reloads templates on runtime
func ReloadTemplates() {
templs := []templateLoader{
templateLoader{
templ: &homeTemplate,
name: "home",
file: "home.html",
},
templ: &searchTemplate,
name: "search",
templ: &uploadTemplate,
name: "upload",
file: "upload.html",
templ: &faqTemplate,
name: "FAQ",
file: "FAQ.html",
templ: &viewTemplate,
name: "view",
file: "view.html",
templ: &viewRegisterTemplate,
name: "user_register",
file: "user/register.html",
templ: &viewRegisterSuccessTemplate,
name: "user_register_success",
file: "user/signup_success.html",
templ: &viewLoginTemplate,
name: "user_login",
file: "user/login.html",
for _, templ := range templs {
t := template.Must(template.New(templ.name).Funcs(FuncMap).ParseFiles(filepath.Join(TemplateDir, "index.html"), filepath.Join(TemplateDir, templ.file)))
t = template.Must(t.ParseGlob(filepath.Join("templates", "_*.html")))
*templ.templ = t