template/interpolate: can specify template data
This commit is contained in:
parent
ff6573ce10
commit
125369d102
@ -8,6 +8,10 @@ import (
|
||||
// Context is the context that an interpolation is done in. This defines
|
||||
// things such as available variables.
|
||||
type Context struct {
|
||||
// Data is the data for the template that is available
|
||||
Data interface{}
|
||||
|
||||
// DisableEnv disables the env function
|
||||
DisableEnv bool
|
||||
}
|
||||
|
||||
@ -25,7 +29,10 @@ func (i *I) Render(ctx *Context) (string, error) {
|
||||
}
|
||||
|
||||
var result bytes.Buffer
|
||||
data := map[string]interface{}{}
|
||||
var data interface{}
|
||||
if ctx != nil {
|
||||
data = ctx.Data
|
||||
}
|
||||
if err := tpl.Execute(&result, data); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user