mirror of
https://github.com/astaxie/beego.git
synced 2024-12-23 07:50:49 +00:00
Add functions passing to template engine callback
This commit is contained in:
parent
10ddb06782
commit
9ee9f81861
12
template.go
12
template.go
@ -31,13 +31,13 @@ import (
|
||||
|
||||
var (
|
||||
beegoTplFuncMap = make(template.FuncMap)
|
||||
// beeTemplates caching map and supported template file extensions.
|
||||
// beeTemplates caching map and supported template file extensions.
|
||||
beeTemplates = make(map[string]TemplateI)
|
||||
templatesLock sync.RWMutex
|
||||
// beeTemplateExt stores the template extension which will build
|
||||
// beeTemplateExt stores the template extension which will build
|
||||
beeTemplateExt = []string{"tpl", "html"}
|
||||
// BeeTemplatePreprocessors stores associations of extension -> preprocessor handler
|
||||
BeeTemplateEngines = map[string]func(root, path string) (TemplateI, error){}
|
||||
// BeeTemplatePreprocessors stores associations of extension -> preprocessor handler
|
||||
BeeTemplateEngines = map[string]func(root, path string, funcs template.FuncMap) (TemplateI, error){}
|
||||
)
|
||||
|
||||
func executeTemplate(wr io.Writer, name string, data interface{}) error {
|
||||
@ -169,7 +169,7 @@ func BuildTemplate(dir string, files ...string) error {
|
||||
fileExt := filepath.Ext(file)[1:]
|
||||
var t TemplateI
|
||||
if fn, ok := BeeTemplateEngines[fileExt]; ok {
|
||||
t, err = fn(self.root, file)
|
||||
t, err = fn(self.root, file, beegoTplFuncMap)
|
||||
}else {
|
||||
t, err = getTemplate(self.root, file, v...)
|
||||
}
|
||||
@ -318,7 +318,7 @@ func DelStaticPath(url string) *App {
|
||||
return BeeApp
|
||||
}
|
||||
|
||||
func AddTemplateEngine(extension string, fn func(root, path string) (TemplateI, error)) *App {
|
||||
func AddTemplateEngine(extension string, fn func(root, path string, funcs template.FuncMap) (TemplateI, error)) *App {
|
||||
AddTemplateExt(extension)
|
||||
BeeTemplateEngines[extension] = fn
|
||||
return BeeApp
|
||||
|
Loading…
Reference in New Issue
Block a user