improving gview with ghttp for controller

This commit is contained in:
John
2019-09-09 23:02:40 +08:00
parent 7f943c6b5f
commit 09da0f7388
4 changed files with 7 additions and 10 deletions

View File

@ -1 +1,2 @@
<h1>MAIN1</h1>
<h1>MAIN1</h1>
<h1>Name: {{.name}}</h1>

View File

@ -1 +1,2 @@
<h1>MAIN2</h1>
<h1>MAIN2</h1>
<h1>Name: {{.name}}</h1>

View File

@ -10,11 +10,8 @@ type Controller struct {
}
func (c *Controller) Index() {
c.View.Display("layout.html")
}
// 不符合规范,不会被自动注册
func (c *Controller) Test(value interface{}) {
c.View.Assign("name", "john")
c.View.Assign("mainTpl", "main/main2.html")
c.View.Display("layout.html")
}

View File

@ -91,18 +91,16 @@ func (view *View) BindFuncMap(funcMap gview.FuncMap) {
}
// 解析并显示指定模板
func (view *View) Display(file ...string) error {
func (view *View) Display(file ...string) {
name := "index.tpl"
if len(file) > 0 {
name = file[0]
}
if content, err := view.Parse(name); err != nil {
view.response.Write("Tpl Parsing Error: " + err.Error())
return err
} else {
view.response.Write(content)
}
return nil
}
// 解析并显示模板内容