Commit 8bbce4e5 authored by Dustin L. Howett's avatar Dustin L. Howett
Browse files

Treat missing subtemplates differently from failed ones.

parent 69df87b6
......@@ -5,6 +5,8 @@ import (
"html/template"
"net/http"
"sync"
log "github.com/Sirupsen/logrus"
)
// viewContext represents the template context passed to each render.
......@@ -64,11 +66,20 @@ type View struct {
func (v *View) subtemplate(vctx *viewContext, name string) template.HTML {
buf := &bytes.Buffer{}
err := v.tmpl.ExecuteTemplate(buf, vctx.page+"_"+name, vctx)
if err != nil {
st := v.tmpl.Lookup(vctx.page + "_" + name)
if st == nil {
// We return an empty snippet here, as a subtemplate failing to exist is non-fatal.
return template.HTML("")
}
err := st.Execute(buf, vctx)
if err != nil {
log.WithFields(log.Fields{
"page": vctx.page,
"subtemplate": name,
"error": err,
}).Error("failed to service subtemplate request")
}
return template.HTML(buf.String())
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment