From a1c84fa1e95977c2e340a6bf208fcab412871d9e Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Fri, 27 Apr 2018 14:49:21 -0700 Subject: [PATCH] Make Session available in the templates --- internal/render/templates.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/render/templates.go b/internal/render/templates.go index 0da1af7..501bf2f 100644 --- a/internal/render/templates.go +++ b/internal/render/templates.go @@ -7,6 +7,7 @@ import ( "strings" "time" + gorilla "github.com/gorilla/sessions" "github.com/kirsle/blog/internal/log" "github.com/kirsle/blog/internal/middleware" "github.com/kirsle/blog/internal/middleware/auth" @@ -35,6 +36,7 @@ type vars struct { RequestDuration time.Duration // Common template variables. + Session *gorilla.Session Message string Flashes []string Error error @@ -77,6 +79,7 @@ func Template(w io.Writer, r *http.Request, path string, data interface{}) error if rw, ok := w.(http.ResponseWriter); ok { rw.Header().Set("Content-Type", "text/html; encoding=UTF-8") session := sessions.Get(r) + v.Session = session // Flashed messages. if flashes := session.Flashes(); len(flashes) > 0 {