tpl: Factor out double Lookup in executeTemplate

This commit is contained in:
Cameron Moore 2016-10-12 01:26:39 -05:00 committed by Bjørn Erik Pedersen
parent 474eb454df
commit 8ddd95e361

View file

@ -117,19 +117,17 @@ func partial(name string, contextList ...interface{}) template.HTML {
}
func executeTemplate(context interface{}, w io.Writer, layouts ...string) {
worked := false
var worked bool
for _, layout := range layouts {
name := layout
if Lookup(name) == nil {
name = layout + ".html"
templ := Lookup(layout)
if templ == nil {
layout += ".html"
templ = Lookup(layout)
}
if templ := Lookup(name); templ != nil {
err := templ.Execute(w, context)
if err != nil {
jww.ERROR.Println(err, "in", name)
if templ != nil {
if err := templ.Execute(w, context); err != nil {
jww.ERROR.Println(err, "in", layout)
}
worked = true
break