From fbf0f6250dadf3fb3ba70b8b8f40b2c265b09939 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Mon, 12 Feb 2024 04:50:44 +0000 Subject: An Operations list page now renders data in table The data is fetched from the database and uses html/template to render the rows in a list. A critical bug was not including the dot in {{ template "main" . }} in the base template. THIS MEANT THAT NO DATA PASSED TO ExecuteTemplate function rendered and took a long time to figure out. --- cmd/web/handlers.go | 4 +--- cmd/web/routes.go | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'cmd') diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index 40ca509..e27b39b 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "html/template" - "log" "net/http" "strconv" @@ -34,7 +33,6 @@ func (app *application) listOperations(w http.ResponseWriter, r *http.Request) { data := operationsTemplateData{ Operations: ops, } - log.Println(data) err = ts.ExecuteTemplate(w, "base", data) if err != nil { @@ -42,7 +40,7 @@ func (app *application) listOperations(w http.ResponseWriter, r *http.Request) { } } -func (app *application) listOrganisation(w http.ResponseWriter, r *http.Request) { +func (app *application) listOrganisations(w http.ResponseWriter, r *http.Request) { files := []string{ "./ui/html/base.tmpl.html", "./ui/html/pages/organisations/list.tmpl.html", diff --git a/cmd/web/routes.go b/cmd/web/routes.go index e21b25d..d23855a 100644 --- a/cmd/web/routes.go +++ b/cmd/web/routes.go @@ -9,7 +9,7 @@ func (app *application) routes() *http.ServeMux { mux.Handle("/static/", http.StripPrefix("/static", fileServer)) mux.HandleFunc("/", app.home) - mux.HandleFunc("/organisation/list", app.listOrganisation) + mux.HandleFunc("/organisation/list", app.listOrganisations) mux.HandleFunc("/organisation/view", app.organisationView) mux.HandleFunc("/organisation/create", app.organisationCreate) mux.HandleFunc("/operation/list", app.listOperations) -- cgit v1.2.3