// Created on savesnippets.com · https://savesnippets.com/VGTdxzQ3ysR7x3 package main import ( "os" "text/template" ) const emailTmpl = `Hi {{.Name}}, Thanks for signing up to {{.Product}}! You're on the {{.Plan}} plan. {{if .Trial}}You have {{.TrialDays}} days of free trial. {{end -}} Visit https://{{.Product | lower}}.com/dashboard to get started. ` func main() { funcs := template.FuncMap{ "lower": strings.ToLower, } t := template.Must(template.New("email").Funcs(funcs).Parse(emailTmpl)) data := struct { Name, Product, Plan string Trial bool TrialDays int }{ Name: "Alice", Product: "MyApp", Plan: "Pro", Trial: true, TrialDays: 14, } t.Execute(os.Stdout, data) } // import strings — omitted above for brevity import "strings"