1: Page Layout
A html page of: head portion, body portion, the inside css, internal js, outreach css, JS outreach of these parts. Therefore, a layout file will need to be split for these.
2> layout.go a new controller. An example of the preparation of the layout file references. Specific code as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
package controllers
import (
"github.com/astaxie/beego"
)
type LayoutController
struct
{
beego.Controller
}
//登录页面
func (c *LayoutController) Get() {
//布局页面
c.Layout =
"layout.html"
//内容页面
c.TplName =
"content.html"
//其他的部分
c.LayoutSections = make(map[
string
]
string
)
//页面使用的css部分
c.LayoutSections[
"HtmlHead"
] =
"head.tpl"
//页面使用的js部分
c.LayoutSections[
"Scripts"
] =
"scripts.tpl"
//页面的补充部分,可做为底部的版权部分时候
c.LayoutSections[
"SideBar"
] =
"sidebar.tpl"
}
|
3> New page layout, as shown in particular in FIG.
4> Add the code in the router, compile and run the project, revision errors, check the running effect
5> operating results as follows:
6> Layout.html specific code as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<!DOCTYPE html>
<html>
<head>
<title>布局页面</title>
<meta name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
>
<link rel=
"stylesheet"
href=
"/static/bootstrap/css/bootstrap.min.css"
/>
<link rel=
"stylesheet"
href=
"/static/bootstrap/css/bootstrap-theme.min.css"
/>
<script type=
"text/javascript"
src=
"/static/js/jquery-2.1.1.min.js"
></script>
<script type=
"text/javascript"
src=
"/static/bootstrap/js/bootstrap.min.js"
></script>
{{.HtmlHead}}
</head>
<body>
<div
class
=
"container"
>
{{.LayoutContent}}
</div>
<div
class
=
"sidebar"
>
{{.SideBar}}
</div>
{{.Scripts}}
</body>
</html>
|
7> This week Beego study notes will not be updated. I think again there are those who need to record learning points.