Add functions to notification templates (#1263)

This commit is contained in:
Justin Beaty 2023-03-25 23:30:35 -07:00 committed by GitHub
parent d1d0922a8c
commit a95510260d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,6 +12,7 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/Masterminds/sprig/v3"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/jmoiron/sqlx/types" "github.com/jmoiron/sqlx/types"
"github.com/knadh/goyesql/v2" "github.com/knadh/goyesql/v2"
@ -602,6 +603,12 @@ func initNotifTemplates(path string, fs stuffbin.FileSystem, i *i18n.I18n, cs *c
"LogoURL": func() string { "LogoURL": func() string {
return cs.LogoURL return cs.LogoURL
}, },
"Date": func(layout string) string {
if layout == "" {
layout = time.ANSIC
}
return time.Now().Format(layout)
},
"L": func() *i18n.I18n { "L": func() *i18n.I18n {
return i 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") tpls, err := stuffbin.ParseTemplatesGlob(funcs, fs, "/static/email-templates/*.html")
if err != nil { if err != nil {
lo.Fatalf("error parsing e-mail notif templates: %v", err) lo.Fatalf("error parsing e-mail notif templates: %v", err)