summaryrefslogtreecommitdiff
path: root/static/emailtemplates.go
blob: 5e3cf0688c6e51110e60e41cacd128b30d5517d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package static

import (
	"bytes"
	_ "embed"
	"html/template"
)

//go:embed "emailconfirm.html.tmpl"
var emailConfirmTemplate []byte

//go:embed "golive.html.tmpl"
var goLiveTemplate []byte

// GetEmailConfirmTemplate will return the email confirmation template.
func GetEmailConfirmTemplate() string {
	return string(getFileSystemStaticFileOrDefault("emailconfirm.html.tmpl", emailConfirmTemplate))
}

// GetEmailLiveTemplate will return the email live template.
func GetEmailLiveTemplate() string {
	return string(getFileSystemStaticFileOrDefault("golive.html.tmpl", goLiveTemplate))
}

// GetEmailConfirmTemplateWithContent will return the email confirmation
// template with content populated.
func GetEmailConfirmTemplateWithContent(title, subtitle, footer, button, buttonLink string) (string, error) {
	type content struct {
		Title         string
		Subtitle      string
		SecondaryText string
		Button        string
		ButtonLink    string
		ShowFooter    bool
	}

	data := content{
		Title:         title,
		Subtitle:      subtitle,
		SecondaryText: footer,
		Button:        button,
		ButtonLink:    buttonLink,
		ShowFooter:    false,
	}

	templateBytes := GetEmailConfirmTemplate()

	t, err := template.New("emailConfirm").Parse(templateBytes)
	if err != nil {
		return "", err
	}
	var tpl bytes.Buffer
	if err := t.Execute(&tpl, data); err != nil {
		return "", err
	}
	return tpl.String(), nil
}