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.
Showing
1 changed file
with
20 additions
and
0 deletions
| ... | @@ -38,6 +38,7 @@ type Controller struct { | ... | @@ -38,6 +38,7 @@ type Controller struct { |
| 38 | actionName string | 38 | actionName string |
| 39 | TplNames string | 39 | TplNames string |
| 40 | Layout string | 40 | Layout string |
| 41 | LayoutSections map[string]string // the key is the section name and the value is the template name | ||
| 41 | TplExt string | 42 | TplExt string |
| 42 | _xsrf_token string | 43 | _xsrf_token string |
| 43 | gotofunc string | 44 | gotofunc string |
| ... | @@ -161,6 +162,25 @@ func (c *Controller) RenderBytes() ([]byte, error) { | ... | @@ -161,6 +162,25 @@ func (c *Controller) RenderBytes() ([]byte, error) { |
| 161 | } | 162 | } |
| 162 | tplcontent, _ := ioutil.ReadAll(newbytes) | 163 | tplcontent, _ := ioutil.ReadAll(newbytes) |
| 163 | c.Data["LayoutContent"] = template.HTML(string(tplcontent)) | 164 | c.Data["LayoutContent"] = template.HTML(string(tplcontent)) |
| 165 | |||
| 166 | if c.LayoutSections != nil { | ||
| 167 | for sectionName, sectionTpl := range c.LayoutSections { | ||
| 168 | if (sectionTpl == "") { | ||
| 169 | c.Data[sectionName] = "" | ||
| 170 | continue | ||
| 171 | } | ||
| 172 | |||
| 173 | sectionBytes := bytes.NewBufferString("") | ||
| 174 | err = BeeTemplates[sectionTpl].ExecuteTemplate(sectionBytes, sectionTpl, c.Data) | ||
| 175 | if err != nil { | ||
| 176 | Trace("template Execute err:", err) | ||
| 177 | return nil, err | ||
| 178 | } | ||
| 179 | sectionContent, _ := ioutil.ReadAll(sectionBytes) | ||
| 180 | c.Data[sectionName] = template.HTML(string(sectionContent)) | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 164 | ibytes := bytes.NewBufferString("") | 184 | ibytes := bytes.NewBufferString("") |
| 165 | err = BeeTemplates[c.Layout].ExecuteTemplate(ibytes, c.Layout, c.Data) | 185 | err = BeeTemplates[c.Layout].ExecuteTemplate(ibytes, c.Layout, c.Data) |
| 166 | if err != nil { | 186 | if err != nil { | ... | ... |
-
Please register or sign in to post a comment