Skip to content

Latest commit

 

History

History
40 lines (33 loc) · 657 Bytes

2020-07-30-template_output_as_string.md

File metadata and controls

40 lines (33 loc) · 657 Bytes

Template output as string

Category golang
Added on 2020-07-30
Source source
tplSource := `
Test template with {{.Key}}
`

t := template.New("example").Parse(tplSource)

data := struct{
    Key string
}{
    Key: "variable key"
}

var tpl bytes.Buffer
if err := t.Execute(&tpl, data); err != nil {
    return err
}

result := tpl.String() // or tpl.Bytes()