Query regarding text email template with place holders

I have the following requirement:

  • we need to send customized text / html based email
  • we create a template file with place holders for each type of email
  • we have to pass a map to the template and it should return the body of the email

Please note that I don’t want to iterate through the map and since there could be numerous email templates, i cant create a struct for each.
Below is an example of what the requirement is:

Template - the quick {{. color}} {{. animal1}} jumped over the lazy {{. animal2}}
Input to the template parser - map with key / values - [“color”:“brown”, “animal1”:dog, “animal2”:“fox”]
Expected output - the quick brown dog jumped over the lazy fox

Kindly suggest how to achieve this.


Have you checked out the html/template docs? https://golang.org/pkg/html/template/

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.