From 9ee9f81861be6f2b0033756ee4d31ddd4d663df0 Mon Sep 17 00:00:00 2001 From: saturn4er Date: Mon, 7 Mar 2016 09:37:47 +0200 Subject: [PATCH] Add functions passing to template engine callback --- template.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/template.go b/template.go index 882e2c1f..b53e466e 100644 --- a/template.go +++ b/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