fix: render base.html layout instead of bare page templates
ExecuteTemplate now renders base.html which calls {{template "content" .}},
so the full layout (header, footer, styles) wraps each page.
This commit is contained in:
@@ -80,12 +80,16 @@ func (h *Handler) profilePage(w http.ResponseWriter, r *http.Request) {
|
||||
h.render(w, "profile.html", pageData{Title: "Профиль"})
|
||||
}
|
||||
|
||||
// render executes the named template with data, writing to w.
|
||||
func (h *Handler) render(w http.ResponseWriter, name string, data pageData) {
|
||||
// render executes the base layout template with the given content page.
|
||||
// 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")
|
||||
if err := h.tmpl.ExecuteTemplate(w, name, data); err != nil {
|
||||
log.Printf("Template error (%s): %v", name, err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
if err := h.tmpl.ExecuteTemplate(w, "base.html", data); err != nil {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user