Render executes the template with the specified data as the dot object and returns the result as plain string.
(data any)
| 15 | // Render executes the template with the specified data as the dot object |
| 16 | // and returns the result as plain string. |
| 17 | func (r *Renderer) Render(data any) (string, error) { |
| 18 | if r.parseError != nil { |
| 19 | return "", r.parseError |
| 20 | } |
| 21 | |
| 22 | if r.template == nil { |
| 23 | return "", errors.New("invalid or nil template") |
| 24 | } |
| 25 | |
| 26 | buf := new(bytes.Buffer) |
| 27 | |
| 28 | if err := r.template.Execute(buf, data); err != nil { |
| 29 | return "", err |
| 30 | } |
| 31 | |
| 32 | return buf.String(), nil |
| 33 | } |