Centralizing the template execution logic in one place

This commit is contained in:
spf13 2014-06-06 16:38:19 -04:00
parent c297d7451f
commit 4483a6655a

View file

@ -508,25 +508,7 @@ func (p *Page) Render(layout ...string) template.HTML {
curLayout = layout[0] curLayout = layout[0]
} }
return bytesToHTML(p.ExecuteTemplate(curLayout).Bytes()) return ExecuteTemplateToHTML(p, p.Layout(curLayout)...)
}
func (p *Page) ExecuteTemplate(layout string) *bytes.Buffer {
l := p.Layout(layout)
buffer := new(bytes.Buffer)
worked := false
for _, layout := range l {
if p.Tmpl.Lookup(layout) != nil {
p.Tmpl.ExecuteTemplate(buffer, layout, p)
worked = true
break
}
}
if !worked {
jww.ERROR.Println("Unable to render", layout, ".")
jww.ERROR.Println("Expecting to find a template in either the theme/layouts or /layouts in one of the following relative locations", l)
}
return buffer
} }
func (page *Page) guessMarkupType() string { func (page *Page) guessMarkupType() string {