add layout example for package gview

This commit is contained in:
John
2019-04-23 19:11:38 +08:00
parent c1aa5eb717
commit ecd86e3a12
11 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package main
import (
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/net/ghttp"
)
func main() {
s := g.Server()
s.BindHandler("/", func(r *ghttp.Request) {
r.Response.WriteTpl("layout.html", nil)
})
s.SetPort(8199)
s.Run()
}

View File

@ -0,0 +1,3 @@
{{define "container"}}
<h1>CONTAINER</h1>
{{end}}

View File

@ -0,0 +1,3 @@
{{define "footer"}}
<h1>FOOTER</h1>
{{end}}

View File

@ -0,0 +1,3 @@
{{define "header"}}
<h1>HEADER</h1>
{{end}}

View File

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>GoFrame Layout</title>
{{template "header"}}
</head>
<body>
<div class="container">
{{template "container"}}
</div>
<div class="footer">
{{template "footer"}}
</div>
</body>
</html>

View File

@ -0,0 +1,23 @@
package main
import (
"github.com/gogf/gf/g"
"github.com/gogf/gf/g/net/ghttp"
)
func main() {
s := g.Server()
s.BindHandler("/main1", func(r *ghttp.Request) {
r.Response.WriteTpl("layout.html", g.Map{
"mainTpl": "main/main1.html",
})
})
s.BindHandler("/main2", func(r *ghttp.Request) {
r.Response.WriteTpl("layout.html", g.Map{
"mainTpl": "main/main2.html",
})
})
g.View().SetPath("template")
s.SetPort(8199)
s.Run()
}

View File

@ -0,0 +1 @@
<h1>FOOTER</h1>

View File

@ -0,0 +1 @@
<h1>HEADER</h1>

View File

@ -0,0 +1,3 @@
{{include "header.html" .}}
{{include .mainTpl .}}
{{include "footer.html" .}}

View File

@ -0,0 +1 @@
<h1>MAIN1</h1>

View File

@ -0,0 +1 @@
<h1>MAIN2</h1>