From 6297ec319534ebc140058089a8eced6cd8d2da3c Mon Sep 17 00:00:00 2001 From: Isus Ramzy <128253026+IsusRamzy@users.noreply.github.com> Date: Fri, 9 Aug 2024 18:33:26 +0300 Subject: [PATCH 1/2] Update echo.go --- echo.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/echo.go b/echo.go index dbb98113a..f43956e5b 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) From e9a6c83e6b90fe50dbd4613af05ecb05181cd81e Mon Sep 17 00:00:00 2001 From: Isus Ramzy <128253026+IsusRamzy@users.noreply.github.com> Date: Sat, 10 Aug 2024 18:28:27 +0300 Subject: [PATCH 2/2] Update echo.go --- echo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/echo.go b/echo.go index f43956e5b..67d97ccf2 100644 --- a/echo.go +++ b/echo.go @@ -403,7 +403,7 @@ func (t *TemplateRenderer) Render(w io.Writer, name string, data interface{}, c return t.templates.ExecuteTemplate(w, name, data) } -func beginTemplates(e *Echo) { +func BeginTemplates(e *Echo) { templates := template.Must(template.ParseGlob("templates/*.html")) e.Renderer = renderer }