pcmt/handlers/templates.go
leo 9dbc475145
All checks were successful
continuous-integration/drone/push Build is passing
go: implement the Echo renderer for templates
2023-05-06 21:50:35 +02:00

23 lines
403 B
Go

package handlers
import (
"html/template"
"io"
"github.com/labstack/echo/v4"
)
type TemplateRenderer struct {
tmpls *template.Template
}
var Renderer = &TemplateRenderer{tmpls: template.New("")}
func (t *TemplateRenderer) Render(w io.Writer, name string, data any, c echo.Context) error {
c.Logger().Debugf("rendering template %s", name)
tpl := getTmpl(name)
return tpl.Execute(w, data)
}