Beego框架學習---layout的使用
阿新 • • 發佈:2018-01-26
css route mark tom 界面 span 組件 page mes
Beego框架學習---layout的使用
在管理系統中,管理菜單的界面是固定的,會變化的只是中間的部分。我就在想,是不是跟angular的“組件模塊的router-outlet一樣”每次只用修改中間的內容部分,菜單和導航欄不變。
果不其然,beego框架也是支持layout的設計。
首先,在views目錄下創建一個
layout.html
,這個html文件中把整個的頁面框架設計好,在需要替換的內容的地方寫成{{.layoutContent}}<div> <!-- Content Header (Page header) --> {{.ContentHead}} <!-- Main content --> {{.LayoutContent }} </div>
然後再路由轉到的controller的方法內,定義頁面的布局和內容。
func (this *Usercontroller)Get() { this.Data["Title"] = "用戶管理" this.Layout = "layout.html" this.LayoutSections = make(map[string]string) this.LayoutSections["CustomJs"] = "customjs/user.html" this.LayoutSections["CustomCss"] = "" this.LayoutSections["ContentHead"
此時,beego就會首先解析TplNames指定的文件,獲取內容賦值給LayoutContent,然後最後渲染
layout.html
文件。展示user.html
頁面
Beego框架學習---layout的使用