summaryrefslogtreecommitdiffstats
path: root/cmd/web/handlers.go
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-02-15 16:06:53 +0000
committerMatthew Lemon <y@yulqen.org>2024-02-15 16:10:20 +0000
commitf77f7f45e6e51edafcebf37b1253fa5db8e775ef (patch)
treeac526fb1dd43a96db4b7a501d65c6eb3e1edcf55 /cmd/web/handlers.go
parentdd24746bcde550cffaf698a0c9c727e869e3cfb3 (diff)
Implementing the templateCache in organisations list
The render() function at the moment requires a templateData struct to be passed to it, but prior to this commit, that struct only had an Operations field in it. We have now added an Organisations field too - the thinking being that we only add the data we need for the page in question and the other fields remain as nil values. As of this commit - the slice of Organisations passed is not rendered correctly by the template - just a raw data dump to prove it works.
Diffstat (limited to 'cmd/web/handlers.go')
-rw-r--r--cmd/web/handlers.go20
1 files changed, 8 insertions, 12 deletions
diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go
index 4d90469..b487eca 100644
--- a/cmd/web/handlers.go
+++ b/cmd/web/handlers.go
@@ -3,7 +3,6 @@ package main
import (
"errors"
"fmt"
- "html/template"
"net/http"
"strconv"
@@ -40,22 +39,19 @@ func (app *application) listOperations(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",
- "./ui/html/partials/nav.tmpl.html",
- }
- ts, err := template.ParseFiles(files...)
+ latest, err := app.organisations.Latest()
if err != nil {
- app.serverError(w, r, err) // Use the serverError() helper
+ app.serverError(w, r, err)
return
}
- err = ts.ExecuteTemplate(w, "base", nil)
- if err != nil {
- app.serverError(w, r, err) // Use the serverError() helper
- }
+ // We are putting latest in the Organisations field of templateData and leaving
+ // templateData.Operations as the nil value because we don't need Operations in this
+ // page, of course.
+ app.render(w, r, http.StatusOK, "organisations_list.tmpl.html", templateData{
+ Organisations: latest,
+ })
}
func (app *application) home(w http.ResponseWriter, r *http.Request) {