mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 11:20:56 +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 (
|
var (
|
||||||
beegoTplFuncMap = make(template.FuncMap)
|
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)
|
beeTemplates = make(map[string]TemplateI)
|
||||||
templatesLock sync.RWMutex
|
templatesLock sync.RWMutex
|
||||||
// beeTemplateExt stores the template extension which will build
|
// beeTemplateExt stores the template extension which will build
|
||||||
beeTemplateExt = []string{"tpl", "html"}
|
beeTemplateExt = []string{"tpl", "html"}
|
||||||
// BeeTemplatePreprocessors stores associations of extension -> preprocessor handler
|
// BeeTemplatePreprocessors stores associations of extension -> preprocessor handler
|
||||||
BeeTemplateEngines = map[string]func(root, path string) (TemplateI, error){}
|
BeeTemplateEngines = map[string]func(root, path string, funcs template.FuncMap) (TemplateI, error){}
|
||||||
)
|
)
|
||||||
|
|
||||||
func executeTemplate(wr io.Writer, name string, data interface{}) 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:]
|
fileExt := filepath.Ext(file)[1:]
|
||||||
var t TemplateI
|
var t TemplateI
|
||||||
if fn, ok := BeeTemplateEngines[fileExt]; ok {
|
if fn, ok := BeeTemplateEngines[fileExt]; ok {
|
||||||
t, err = fn(self.root, file)
|
t, err = fn(self.root, file, beegoTplFuncMap)
|
||||||
}else {
|
}else {
|
||||||
t, err = getTemplate(self.root, file, v...)
|
t, err = getTemplate(self.root, file, v...)
|
||||||
}
|
}
|
||||||
@ -318,7 +318,7 @@ func DelStaticPath(url string) *App {
|
|||||||
return BeeApp
|
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)
|
AddTemplateExt(extension)
|
||||||
BeeTemplateEngines[extension] = fn
|
BeeTemplateEngines[extension] = fn
|
||||||
return BeeApp
|
return BeeApp
|
||||||
|
Loading…
Reference in New Issue
Block a user