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
import (
"fmt"
"html/template"
"net/http"
@ -22,11 +23,14 @@ func helpTemplate(w http.ResponseWriter, r *http.Request) {
BarcodeOptions: barcodeOptions,
}
tmpl := template.Must(template.New("base.html").ParseFiles("templates/base.html", "templates/help.html"))
err := tmpl.Execute(w, data)
tmpl, err := template.ParseFiles("templates/base.html", "templates/help.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
fmt.Println("Error parsing templates: ", err)
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)
}
}