diff --git a/gin.go b/gin.go index 8b6d17d5..0f4753e2 100644 --- a/gin.go +++ b/gin.go @@ -82,22 +82,26 @@ func Default() *Engine { } func (engine *Engine) LoadHTMLGlob(pattern string) { - templ := template.Must(template.ParseGlob(pattern)) - engine.SetHTMLTemplate(templ) -} - -func (engine *Engine) LoadHTMLFiles(files ...string) { - templ := template.Must(template.ParseFiles(files...)) - engine.SetHTMLTemplate(templ) -} - -func (engine *Engine) SetHTMLTemplate(templ *template.Template) { if gin_mode == debugCode { engine.HTMLRender = render.HTMLDebug } else { - engine.HTMLRender = render.HTMLRender{ - Template: templ, - } + templ := template.Must(template.ParseGlob(pattern)) + engine.SetHTMLTemplate(templ) + } +} + +func (engine *Engine) LoadHTMLFiles(files ...string) { + if gin_mode == debugCode { + engine.HTMLRender = render.HTMLDebug + } else { + templ := template.Must(template.ParseFiles(files...)) + engine.SetHTMLTemplate(templ) + } +} + +func (engine *Engine) SetHTMLTemplate(templ *template.Template) { + engine.HTMLRender = render.HTMLRender{ + Template: templ, } } diff --git a/render/render.go b/render/render.go index 57a59fe1..bc982a30 100644 --- a/render/render.go +++ b/render/render.go @@ -82,7 +82,11 @@ func (_ htmlDebugRender) Render(w http.ResponseWriter, code int, data ...interfa writeHeader(w, code, "text/html") file := data[0].(string) obj := data[1] - return template.New(file).Execute(w, obj) + t, err := template.ParseFiles(file) + if err != nil { + return err + } + return t.ExecuteTemplate(w, file, obj) } func (html HTMLRender) Render(w http.ResponseWriter, code int, data ...interface{}) error {