mirror of
https://gitee.com/johng/gf
synced 2026-06-07 10:22:11 +08:00
add layout example for package gview
This commit is contained in:
15
geg/os/gview/layout/layout1/main.go
Normal file
15
geg/os/gview/layout/layout1/main.go
Normal 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()
|
||||
}
|
||||
3
geg/os/gview/layout/layout1/template/container.html
Normal file
3
geg/os/gview/layout/layout1/template/container.html
Normal file
@ -0,0 +1,3 @@
|
||||
{{define "container"}}
|
||||
<h1>CONTAINER</h1>
|
||||
{{end}}
|
||||
3
geg/os/gview/layout/layout1/template/footer.html
Normal file
3
geg/os/gview/layout/layout1/template/footer.html
Normal file
@ -0,0 +1,3 @@
|
||||
{{define "footer"}}
|
||||
<h1>FOOTER</h1>
|
||||
{{end}}
|
||||
3
geg/os/gview/layout/layout1/template/header.html
Normal file
3
geg/os/gview/layout/layout1/template/header.html
Normal file
@ -0,0 +1,3 @@
|
||||
{{define "header"}}
|
||||
<h1>HEADER</h1>
|
||||
{{end}}
|
||||
15
geg/os/gview/layout/layout1/template/layout.html
Normal file
15
geg/os/gview/layout/layout1/template/layout.html
Normal 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>
|
||||
23
geg/os/gview/layout/layout2/main.go
Normal file
23
geg/os/gview/layout/layout2/main.go
Normal 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()
|
||||
}
|
||||
1
geg/os/gview/layout/layout2/template/footer.html
Normal file
1
geg/os/gview/layout/layout2/template/footer.html
Normal file
@ -0,0 +1 @@
|
||||
<h1>FOOTER</h1>
|
||||
1
geg/os/gview/layout/layout2/template/header.html
Normal file
1
geg/os/gview/layout/layout2/template/header.html
Normal file
@ -0,0 +1 @@
|
||||
<h1>HEADER</h1>
|
||||
3
geg/os/gview/layout/layout2/template/layout.html
Normal file
3
geg/os/gview/layout/layout2/template/layout.html
Normal file
@ -0,0 +1,3 @@
|
||||
{{include "header.html" .}}
|
||||
{{include .mainTpl .}}
|
||||
{{include "footer.html" .}}
|
||||
1
geg/os/gview/layout/layout2/template/main/main1.html
Normal file
1
geg/os/gview/layout/layout2/template/main/main1.html
Normal file
@ -0,0 +1 @@
|
||||
<h1>MAIN1</h1>
|
||||
1
geg/os/gview/layout/layout2/template/main/main2.html
Normal file
1
geg/os/gview/layout/layout2/template/main/main2.html
Normal file
@ -0,0 +1 @@
|
||||
<h1>MAIN2</h1>
|
||||
Reference in New Issue
Block a user