1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 13:30:56 +00:00
This commit is contained in:
smithfox 2013-09-26 18:33:01 +08:00
parent 02c2e16253
commit bed0fe2218

View File

@ -160,6 +160,19 @@ func getTemplate(root, file string, others ...string) (t *template.Template, err
t = template.New(file).Delims(TemplateLeft, TemplateRight).Funcs(beegoTplFuncMap) t = template.New(file).Delims(TemplateLeft, TemplateRight).Funcs(beegoTplFuncMap)
var submods [][]string var submods [][]string
t, submods, err = getTplDeep(root, file, t) t, submods, err = getTplDeep(root, file, t)
if err != nil {
return nil, err
}
t, err = _getTemplate(t, root, submods, others...)
if err != nil {
return nil, err
}
return
}
func _getTemplate(t0 *template.Template, root string, submods [][]string, others ...string) (t *template.Template, err error) {
t = t0
for _, m := range submods { for _, m := range submods {
if len(m) == 2 { if len(m) == 2 {
templ := t.Lookup(m[1]) templ := t.Lookup(m[1])
@ -169,9 +182,12 @@ func getTemplate(root, file string, others ...string) (t *template.Template, err
//first check filename //first check filename
for _, otherfile := range others { for _, otherfile := range others {
if otherfile == m[1] { if otherfile == m[1] {
t, _, err = getTplDeep(root, otherfile, t) var submods1 [][]string
t, submods1, err = getTplDeep(root, otherfile, t)
if err != nil { if err != nil {
Trace("template parse file err:", err) Trace("template parse file err:", err)
} else if submods1 != nil && len(submods1) > 0 {
t, err = _getTemplate(t, root, submods1, others...)
} }
break break
} }
@ -187,9 +203,12 @@ func getTemplate(root, file string, others ...string) (t *template.Template, err
allsub := reg.FindAllStringSubmatch(string(data), -1) allsub := reg.FindAllStringSubmatch(string(data), -1)
for _, sub := range allsub { for _, sub := range allsub {
if len(sub) == 2 && sub[1] == m[1] { if len(sub) == 2 && sub[1] == m[1] {
t, _, err = getTplDeep(root, otherfile, t) var submods1 [][]string
t, submods1, err = getTplDeep(root, otherfile, t)
if err != nil { if err != nil {
Trace("template parse file err:", err) Trace("template parse file err:", err)
} else if submods1 != nil && len(submods1) > 0 {
t, err = _getTemplate(t, root, submods1, others...)
} }
break break
} }
@ -198,9 +217,5 @@ func getTemplate(root, file string, others ...string) (t *template.Template, err
} }
} }
if err != nil {
return nil, err
}
return return
} }