mirror of
https://github.com/astaxie/beego.git
synced 2025-07-04 02:50:19 +00:00
增加编译模版函数BuildTemplate可变参数,使之支持单个或多个模版的编译,同时针对开发模式,每个请求只编译当前请求相关模版
增加编译模版函数BuildTemplate可变参数,使之支持单个或多个模版的编译,同时针对开发模式,每个请求只编译当前请求相关模版,不再每次请求都编译全部模版
This commit is contained in:
14
template.go
14
template.go
@ -127,7 +127,7 @@ func AddTemplateExt(ext string) {
|
||||
|
||||
// build all template files in a directory.
|
||||
// it makes beego can render any template file in view directory.
|
||||
func BuildTemplate(dir string) error {
|
||||
func BuildTemplate(dir string, files... string) error {
|
||||
if _, err := os.Stat(dir); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil
|
||||
@ -148,11 +148,13 @@ func BuildTemplate(dir string) error {
|
||||
}
|
||||
for _, v := range self.files {
|
||||
for _, file := range v {
|
||||
t, err := getTemplate(self.root, file, v...)
|
||||
if err != nil {
|
||||
Trace("parse template err:", file, err)
|
||||
} else {
|
||||
BeeTemplates[file] = t
|
||||
if (files == nil || utils.InSlice(file, files)) {
|
||||
t, err := getTemplate(self.root, file, v...)
|
||||
if err != nil {
|
||||
Trace("parse template err:", file, err)
|
||||
} else {
|
||||
BeeTemplates[file] = t
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user