Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions controllers/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,11 @@ func (this *BaseController) ShowHtml(tpl ...string) {
this.Data["breadcrumbs"] = this.ShowBreadcrumbs()
this.Data["menus"] = libs.ShowMenu(this.controllerName, this.actionName)

if len(libs.Template.Data) > 0 {
for name, value := range libs.Template.Data {
layoutData := this.GetSession("grabc_layout_data")

if layoutData != nil {
d := layoutData.(map[string]interface{})
for name, value := range d {
if _, isExist := this.Data[name]; isExist {
panic("设置layout数据失败,因为" + name + "已经存在")
}
Expand Down
8 changes: 7 additions & 1 deletion grabc.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ func SetLayout(layoutName string, layoutPath string) {

//设置grabc的模板的数据
func AddLayoutData(name string, value interface{}) {
libs.Template.Data[name] = value
if libs.BeegoC.GetSession("grabc_layout_data") == nil {
libs.BeegoC.SetSession("grabc_layout_data", make(map[string]interface{}, 0))
}

data := libs.BeegoC.GetSession("grabc_layout_data").(map[string]interface{})
data[name] = value
libs.BeegoC.SetSession("grabc_layout_data", data)
}

//设置grabc模板的路径
Expand Down
3 changes: 0 additions & 3 deletions libs/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ var Template GrabcTemplate

func init() {
Template = GrabcTemplate{}
Template.Data = make(map[string]interface{}, 0)

}

type GrabcTemplate struct {
LayoutName string
LayoutPath string
ViewPath string
Data map[string]interface{}
}

func (this *GrabcTemplate) GlobalCss() string {
Expand Down