1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-26 23:24:38 +01:00
liquid/template.go

32 lines
668 B
Go
Raw Normal View History

2017-06-27 13:43:42 +02:00
package liquid
import (
"bytes"
"github.com/osteele/liquid/chunks"
)
2017-06-30 22:13:18 +02:00
type template struct {
ast chunks.ASTNode
settings chunks.Settings
}
2017-06-29 02:49:38 +02:00
// Render executes the template within the bindings environment.
2017-07-03 03:17:04 +02:00
func (t *template) Render(b Bindings) ([]byte, error) {
2017-06-27 13:43:42 +02:00
buf := new(bytes.Buffer)
err := chunks.Render(t.ast, buf, chunks.NewContext(b, t.settings))
2017-06-27 13:43:42 +02:00
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
// RenderString is a convenience wrapper for Render, that has string input and output.
2017-07-03 03:17:04 +02:00
func (t *template) RenderString(b Bindings) (string, error) {
bs, err := t.Render(b)
2017-06-27 13:43:42 +02:00
if err != nil {
return "", err
}
2017-07-03 03:17:04 +02:00
return string(bs), nil
2017-06-27 13:43:42 +02:00
}