leo
122ea638c9
All checks were successful
continuous-integration/drone/push Build is passing
* create pkg 'modules/template' * move template rendering code from 'handlers' to 'modules/template' * update call sites * walk the 'templates' dir to discover nested hierarchies * solidify LiveMode handling (vs embedded assets) * break out funcMap to it's own file * general clean-up
23 lines
384 B
Go
23 lines
384 B
Go
package template
|
|
|
|
import (
|
|
"html/template"
|
|
"io"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
type TplRenderer struct {
|
|
tmpls *template.Template
|
|
}
|
|
|
|
var Renderer = &TplRenderer{tmpls: template.New("")}
|
|
|
|
func (t *TplRenderer) Render(w io.Writer, name string, data any, c echo.Context) error {
|
|
c.Logger().Debugf("rendering template %s", name)
|
|
|
|
tpl := Get(name)
|
|
|
|
return tpl.Execute(w, data)
|
|
}
|