shithub: hugo

Download patch

ref: 8ddd95e3614718b5ff335fe484c451ca45b9a345
parent: 474eb454dfb6e150d0a7a79edf32906f7a2355d8
author: Cameron Moore <[email protected]>
date: Tue Oct 11 21:26:39 EDT 2016

tpl: Factor out double Lookup in executeTemplate


--- a/tpl/template.go
+++ b/tpl/template.go
@@ -117,19 +117,17 @@
 }
 
 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