zoukankan      html  css  js  c++  java
  • Beego框架学习---layout的使用

    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"] = "contenthead2.html"
    	this.LayoutSections["Menu"] = "menu.html"
    	this.TplName = "user.html"
    	this.Data["undesgin"], _ = mgo.Listuser()
    
    • 此时,beego就会首先解析TplNames指定的文件,获取内容赋值给LayoutContent,然后最后渲染layout.html文件。展示user.html页面
  • 相关阅读:
    通过JavaScript垃圾回收机制来理解WeakSet/WeakMap中对象的弱引用
    json处理
    dotenv 加载本地环境变量
    各种ast库
    类型检测库
    npm 加解密库
    用计算机语言的爱情表白
    情侣在招聘会上搂抱招致企业反感
    《软件性能测试与LoadRunner实战》网上订购问题
    F1赛车的起源
  • 原文地址:https://www.cnblogs.com/liyao0312/p/8359442.html
Copyright © 2011-2022 走看看