From a95510260d6c4f1a63edc5428a65788bb6351c2a Mon Sep 17 00:00:00 2001 From: Justin Beaty <51970393+justinbeaty@users.noreply.github.com> Date: Sat, 25 Mar 2023 23:30:35 -0700 Subject: [PATCH] Add functions to notification templates (#1263) --- cmd/init.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmd/init.go b/cmd/init.go index 99b7929e2..a9c355a7c 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -12,6 +12,7 @@ import ( "syscall" "time" + "github.com/Masterminds/sprig/v3" "github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx/types" "github.com/knadh/goyesql/v2" @@ -602,6 +603,12 @@ func initNotifTemplates(path string, fs stuffbin.FileSystem, i *i18n.I18n, cs *c "LogoURL": func() string { return cs.LogoURL }, + "Date": func(layout string) string { + if layout == "" { + layout = time.ANSIC + } + return time.Now().Format(layout) + }, "L": func() *i18n.I18n { return i }, @@ -610,6 +617,10 @@ func initNotifTemplates(path string, fs stuffbin.FileSystem, i *i18n.I18n, cs *c }, } + for k, v := range sprig.GenericFuncMap() { + funcs[k] = v + } + tpls, err := stuffbin.ParseTemplatesGlob(funcs, fs, "/static/email-templates/*.html") if err != nil { lo.Fatalf("error parsing e-mail notif templates: %v", err)