diff --git a/snippetbox/cmd/web/handlers.go b/snippetbox/cmd/web/handlers.go
index 64fa536..bc2736c 100644
--- a/snippetbox/cmd/web/handlers.go
+++ b/snippetbox/cmd/web/handlers.go
@@ -97,5 +97,7 @@ func (app *application) snippetCreatePost(w http.ResponseWriter, r *http.Request
return
}
+ app.sessionManager.Put(r.Context(), "flash", "Snippet successfully created!")
+
http.Redirect(w, r, fmt.Sprintf("/snippet/view/%d", id), http.StatusSeeOther)
}
diff --git a/snippetbox/cmd/web/helpers.go b/snippetbox/cmd/web/helpers.go
index 6fb5e0c..342efe7 100644
--- a/snippetbox/cmd/web/helpers.go
+++ b/snippetbox/cmd/web/helpers.go
@@ -16,6 +16,7 @@ import (
func (app *application )newTemplateData(r *http.Request) templateData {
return templateData{
CurrentYear: time.Now().Year(),
+ Flash: app.sessionManager.PopString(r.Context(), "flash"),
}
}
diff --git a/snippetbox/cmd/web/templates.go b/snippetbox/cmd/web/templates.go
index b69cc61..7751f24 100644
--- a/snippetbox/cmd/web/templates.go
+++ b/snippetbox/cmd/web/templates.go
@@ -13,6 +13,7 @@ type templateData struct {
Snippet models.Snippet
Snippets []models.Snippet
Form any
+ Flash string
}
// humanDate ...
diff --git a/snippetbox/ui/html/base.tmpl b/snippetbox/ui/html/base.tmpl
index 3e0369d..47adb0d 100644
--- a/snippetbox/ui/html/base.tmpl
+++ b/snippetbox/ui/html/base.tmpl
@@ -14,6 +14,9 @@
{{template "nav" .}}
+ {{with .Flash}}
+ {{.}}
+ {{end}}
{{template "main" .}}