replacing n with <br>

alpha
alex 2024-01-28 22:27:28 +01:00
parent 32348e92a8
commit 24b26a8a87
1 changed files with 12 additions and 0 deletions

View File

@ -134,6 +134,18 @@ func (m *Mail) RenderTemplate() (htmlBody, textBody string, err error) {
htmlBuf := new(bytes.Buffer) htmlBuf := new(bytes.Buffer)
textBuf := new(bytes.Buffer) textBuf := new(bytes.Buffer)
fmt.Println("BODY DATA", m.BodyData)
// parse body data to new map to avoid changing the original map and then replace all \n with <br>
bodyData := make(map[string]interface{})
for key, value := range m.BodyData.(map[string]interface{}) {
bodyData[key] = strings.ReplaceAll(value.(string), "\n", "<br>")
}
m.BodyData = bodyData
if err := htmlTemplate.Execute(htmlBuf, m.BodyData); err != nil { if err := htmlTemplate.Execute(htmlBuf, m.BodyData); err != nil {
return "", "", err return "", "", err
} }