1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-27 09:24:38 +01:00
liquid/template.go
2017-07-04 11:08:57 -04:00

32 lines
666 B
Go

package liquid
import (
"bytes"
"github.com/osteele/liquid/render"
)
type template struct {
ast render.ASTNode
settings render.Config
}
// Render executes the template within the bindings environment.
func (t *template) Render(b Bindings) ([]byte, error) {
buf := new(bytes.Buffer)
err := render.Render(t.ast, buf, render.NewContext(b, t.settings))
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
// RenderString is a convenience wrapper for Render, that has string input and output.
func (t *template) RenderString(b Bindings) (string, error) {
bs, err := t.Render(b)
if err != nil {
return "", err
}
return string(bs), nil
}