Beispiel #1
0
func (this *BaseController) RenderLayout(layoutName string, code ...int) error {
	if len(code) == 0 {
		code = append(code, http.StatusOK)
	}
	render := this.Echo().Render
	for k, v := range this.sectionTpl {
		sectionBytes := bytes.NewBufferString("")
		render(sectionBytes, v, this.Context.GetAll())
		sectionContent, _ := ioutil.ReadAll(sectionBytes)
		this.Set(k, template.HTML(sectionContent))
	}
	return this.Context.Render(code[0], layoutName, this.Context.GetAll())
}
Beispiel #2
0
func (this *BaseController) Render(code ...int) error {
	if len(code) == 0 {
		code = append(code, http.StatusOK)
	}

	if this.Context.Layout != "" {
		render := this.Echo().Render
		for k, v := range this.Context.Sections {
			if v == "" {
				this.Set(k, "")
				continue
			}
			sectionBytes := bytes.NewBufferString("")
			render(sectionBytes, v, this.Context.GetAll())
			sectionContent, _ := ioutil.ReadAll(sectionBytes)
			this.Set(k, template.HTML(sectionContent))
		}
	} else {
		this.Context.Layout = this.Context.Path()
	}
	return this.Context.Render(code[0], this.Context.Layout, this.Context.GetAll())
}