Beego 學習筆記15:佈局頁面

頁面佈局javascript

1>     一個html頁面由:head部分,body部分,內部css,內部js,外聯css,外聯的js這幾部分組成。所以,一個佈局文件也就須要針對這些進行拆分。css

 

 

2>     新建一個layout.go的控制器。編寫一個引用佈局文件的實例。具體代碼以下:html

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>     新建佈局頁面,具體的以下圖所示java

 

 

4>     在路由器中添加代碼,編譯運行項目,修訂錯誤,查看運行的效果jquery

5>     運行效果以下:git

 

 

6>     Layout.html具體的代碼以下:github

 

<!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學習筆記將不會更新了。我再想一想還有那些須要記錄學習點。bootstrap

相關文章
相關標籤/搜索