模板引擎示例程序更新

This commit is contained in:
john
2018-09-03 13:05:41 +08:00
parent 786402ca7e
commit cd99833745
5 changed files with 27 additions and 1 deletions

5
TODO
View File

@ -22,7 +22,10 @@ ghttp增加route name特性并同时支持backend和template(提供内置函
ghttp日志增加客户端IP信息
ghttp.Client自动Close机制
gvalid校验支持当第一个规则失败后便不再校验后续的规则最好做成链式操作
gvalid返回的数据类型调整map[string]map[string]string->map[string]map[string]error这样更容易被第三方框架兼容
检查ghttp.Server超时问题
DONE:
1. gconv完善针对不同类型的判断例如尽量减少sprintf("%v", xxx)来执行string类型的转换

View File

@ -152,3 +152,4 @@ func (view *View) funcInclude(file string, data...map[string]interface{}) templa
}
return template.HTML(content)
}

View File

@ -0,0 +1,19 @@
package main
import (
"fmt"
"gitee.com/johng/gf/g"
"gitee.com/johng/gf/g/os/gfile"
)
func main() {
v := g.View()
// 设置模板目录为当前main.go所在目录下的template目录
v.AddPath(gfile.MainPkgPath() + gfile.Separator + "template")
b, err := v.Parse("index.html", map[string]interface{} {
"k" : "v",
})
fmt.Println(err)
fmt.Println(string(b))
}

View File

@ -0,0 +1,2 @@
{{include "subs/sub.html" .}}

View File

@ -0,0 +1 @@
{{.}}