template/interpolate: support custom functions
This commit is contained in:
parent
241f76b5b1
commit
becd6dacd7
|
@ -45,6 +45,11 @@ func Funcs(ctx *Context) template.FuncMap {
|
||||||
for k, v := range FuncGens {
|
for k, v := range FuncGens {
|
||||||
result[k] = v(ctx)
|
result[k] = v(ctx)
|
||||||
}
|
}
|
||||||
|
if ctx != nil {
|
||||||
|
for k, v := range ctx.Funcs {
|
||||||
|
result[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return template.FuncMap(result)
|
return template.FuncMap(result)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,9 @@ type Context struct {
|
||||||
// Data is the data for the template that is available
|
// Data is the data for the template that is available
|
||||||
Data interface{}
|
Data interface{}
|
||||||
|
|
||||||
|
// Funcs are extra functions available in the template
|
||||||
|
Funcs map[string]interface{}
|
||||||
|
|
||||||
// UserVariables is the mapping of user variables that the
|
// UserVariables is the mapping of user variables that the
|
||||||
// "user" function reads from.
|
// "user" function reads from.
|
||||||
UserVariables map[string]string
|
UserVariables map[string]string
|
||||||
|
|
Loading…
Reference in New Issue