diff --git a/echo.go b/echo.go index dbb98113a..67d97ccf2 100644 --- a/echo.go +++ b/echo.go @@ -61,6 +61,8 @@ import ( "golang.org/x/crypto/acme/autocert" "golang.org/x/net/http2" "golang.org/x/net/http2/h2c" + + "html/template" ) // Echo is the top-level framework instance. @@ -392,6 +394,20 @@ func New() (e *Echo) { return } +type TemplateRenderer struct { + templates *template.Template + renderer := &TemplateRenderer{templates: templates} +} + +func (t *TemplateRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error { + return t.templates.ExecuteTemplate(w, name, data) +} + +func BeginTemplates(e *Echo) { + templates := template.Must(template.ParseGlob("templates/*.html")) + e.Renderer = renderer +} + // NewContext returns a Context instance. func (e *Echo) NewContext(r *http.Request, w http.ResponseWriter) Context { return &context{ @@ -977,6 +993,8 @@ func handlerName(h HandlerFunc) string { return t.String() } + + // // PathUnescape is wraps `url.PathUnescape` // func PathUnescape(s string) (string, error) { // return url.PathUnescape(s)