fix: render base.html layout instead of bare page templates
All checks were successful
CI / lint (push) Successful in 48s
CI / test (push) Successful in 18s
CI / build (push) Successful in 17s
CI / docker (push) Successful in 1m10s

ExecuteTemplate now renders base.html which calls {{template "content" .}},
so the full layout (header, footer, styles) wraps each page.
This commit is contained in:
2026-06-04 06:29:46 +03:00
parent 008d9a129e
commit 394003d8c0

View File

@@ -80,14 +80,18 @@ func (h *Handler) profilePage(w http.ResponseWriter, r *http.Request) {
h.render(w, "profile.html", pageData{Title: "Профиль"}) h.render(w, "profile.html", pageData{Title: "Профиль"})
} }
// render executes the named template with data, writing to w. // render executes the base layout template with the given content page.
func (h *Handler) render(w http.ResponseWriter, name string, data pageData) { // The base.html layout calls {{template "content" .}} which is defined in each page file.
func (h *Handler) render(w http.ResponseWriter, page string, data pageData) {
w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("Content-Type", "text/html; charset=utf-8")
if err := h.tmpl.ExecuteTemplate(w, name, data); err != nil { if err := h.tmpl.ExecuteTemplate(w, "base.html", data); err != nil {
log.Printf("Template error (%s): %v", name, err) log.Printf("Template error (base.html → %s): %v", page, err)
// Fallback: render the page without layout
if err2 := h.tmpl.ExecuteTemplate(w, page, data); err2 != nil {
http.Error(w, "Internal Server Error", http.StatusInternalServerError) http.Error(w, "Internal Server Error", http.StatusInternalServerError)
} }
} }
}
// fallback writes a minimal placeholder when templates are missing. // fallback writes a minimal placeholder when templates are missing.
func fallback(w http.ResponseWriter, title string) { func fallback(w http.ResponseWriter, title string) {