tulip/mail/templates/templates.go

28 lines
493 B
Go
Raw Normal View History

2023-09-24 18:24:16 +01:00
package templates
import (
"embed"
"io"
"log"
"text/template"
)
var (
//go:embed *
embeddedTemplates embed.FS
mailTemplate *template.Template
)
func LoadMailTemplates() (err error) {
mailTemplate, err = template.New("mail").ParseFS(embeddedTemplates, "*.go.txt")
return
}
func RenderMailTemplate(wr io.Writer, name string, data any) {
err := mailTemplate.ExecuteTemplate(wr, name+".go.txt", data)
if err != nil {
log.Printf("Failed to render mail: %s: %s\n", name, err)
}
}