package tem import ( "fmt" "html/template" "net/http" ) var ( Templates *template.Template ) func Load() { func_map := template.FuncMap{} Templates = template.Must(template.New("").Funcs(func_map).ParseGlob("tem/html/**/*.html")) fmt.Println("templates loaded") } func Render( w http.ResponseWriter, r *http.Request, template string, page string, title string, desc string, page_data interface{}, ) { w.WriteHeader(http.StatusOK) data := struct { Host string Page string Title string Desc string Local bool Root bool Data interface{} }{ Host: r.Host, Page: page, Title: title, Desc: desc, Local: true, // (os.Getenv("LOCAL") == "true"), // toggle here for flag testing Root: true, // (os.Getenv("HOST_IDEABRELLA") == strings.ReplaceAll(r.Host, ":3000", "")), Data: page_data, } err := Templates.ExecuteTemplate(w, template, data) if err != nil { fmt.Println(err) } } // for small refreshable templates within pages // so no need for page things like title, desc, etc. func RenderSub( w http.ResponseWriter, r *http.Request, template string, page_data interface{}, ) { w.WriteHeader(http.StatusOK) err := Templates.ExecuteTemplate(w, template, page_data) if err != nil { fmt.Println(err) } }