refactor: common base template for pages

will allow to add common header and stuff
This commit is contained in:
efim
2023-11-13 05:25:02 +00:00
parent b1f2e896b9
commit 1297fcf35d
8 changed files with 140 additions and 55 deletions

View File

@@ -17,23 +17,31 @@ func indexPageRoute(
roomsM rooms.RoomManager,
) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var baseFile = "templates/base.gohtml"
var templFile = "templates/index.gohtml"
session, found := getContextSession(r.Context())
if !found {
log.Printf("/ session not found, should be impossible")
// TODO return error i guess
}
data := struct {
type MainData struct {
SessionStringToken string
SomeString string
SessionToken sessions.SessionData
}{
}
data := pageData {
Base: baseData{
Title: "hello base template title",
},
Content: MainData{
fmt.Sprintf("%+v", session),
"hello!",
session,
},
}
tmpl := template.Must(template.ParseFS(templateFs, templFile))
err := tmpl.Execute(w, data)
tmpl := template.Must(template.ParseFS(templateFs, templFile, baseFile))
err := tmpl.ExecuteTemplate(w, "full-page", data)
if err != nil {
log.Printf("my error in executing template, huh\n %s", err)
}