mirror of
https://github.com/astaxie/beego.git
synced 2025-06-19 13:10:40 +00:00
Added LayoutSections property to Controller
users can define 0 or multipe sections in the Layout template file so all kinds of content such as scripts, css can go to proper sections in the generated html file.
This commit is contained in:
@ -38,6 +38,7 @@ type Controller struct {
|
|||||||
actionName string
|
actionName string
|
||||||
TplNames string
|
TplNames string
|
||||||
Layout string
|
Layout string
|
||||||
|
LayoutSections map[string]string // the key is the section name and the value is the template name
|
||||||
TplExt string
|
TplExt string
|
||||||
_xsrf_token string
|
_xsrf_token string
|
||||||
gotofunc string
|
gotofunc string
|
||||||
@ -161,6 +162,25 @@ func (c *Controller) RenderBytes() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
tplcontent, _ := ioutil.ReadAll(newbytes)
|
tplcontent, _ := ioutil.ReadAll(newbytes)
|
||||||
c.Data["LayoutContent"] = template.HTML(string(tplcontent))
|
c.Data["LayoutContent"] = template.HTML(string(tplcontent))
|
||||||
|
|
||||||
|
if c.LayoutSections != nil {
|
||||||
|
for sectionName, sectionTpl := range c.LayoutSections {
|
||||||
|
if (sectionTpl == "") {
|
||||||
|
c.Data[sectionName] = ""
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
sectionBytes := bytes.NewBufferString("")
|
||||||
|
err = BeeTemplates[sectionTpl].ExecuteTemplate(sectionBytes, sectionTpl, c.Data)
|
||||||
|
if err != nil {
|
||||||
|
Trace("template Execute err:", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
sectionContent, _ := ioutil.ReadAll(sectionBytes)
|
||||||
|
c.Data[sectionName] = template.HTML(string(sectionContent))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ibytes := bytes.NewBufferString("")
|
ibytes := bytes.NewBufferString("")
|
||||||
err = BeeTemplates[c.Layout].ExecuteTemplate(ibytes, c.Layout, c.Data)
|
err = BeeTemplates[c.Layout].ExecuteTemplate(ibytes, c.Layout, c.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user