Tidy up template

This commit is contained in:
Fred Boniface 2023-09-03 20:59:33 +01:00
parent d27625f112
commit 00aa052a61

View File

@ -1,6 +1,7 @@
package web package web
import ( import (
"fmt"
"html/template" "html/template"
"net/http" "net/http"
@ -22,11 +23,14 @@ func helpTemplate(w http.ResponseWriter, r *http.Request) {
BarcodeOptions: barcodeOptions, BarcodeOptions: barcodeOptions,
} }
tmpl := template.Must(template.New("base.html").ParseFiles("templates/base.html", "templates/help.html")) tmpl, err := template.ParseFiles("templates/base.html", "templates/help.html")
err := tmpl.Execute(w, data)
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) fmt.Println("Error parsing templates: ", err)
return http.Error(w, "Unable to parse templates", 500)
}
err = tmpl.Execute(w, data)
if err != nil {
fmt.Println("Error rendering templates: ", err)
http.Error(w, "Unable to render templates", 500)
} }
} }