1:页面布局
一个html页面由:head部分,body部分,内部css,内部js,外联css,外联的js这几部分组成。因此,一个布局文件也就需要针对这些进行拆分。
2> 新建一个layout.go的控制器。编写一个引用布局文件的实例。具体代码如下:
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> 新建布局页面,具体的如下图所示
4> 在路由器中添加代码,编译运行项目,修订错误,查看运行的效果
5> 运行效果如下:
6> Layout.html具体的代码如下:
@H_404_155@
<!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> 这周的Beego学习笔记将不会更新了。我再想想还有那些需要记录学习点。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。