2024-09-18 19:06:33 -04:00
|
|
|
package templates
|
2024-06-06 18:07:30 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
|
|
|
"html/template"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
2024-09-18 19:06:33 -04:00
|
|
|
//go:embed *.html
|
2024-06-06 18:07:30 -04:00
|
|
|
var templatesFS embed.FS
|
|
|
|
|
|
|
|
type Template struct {
|
|
|
|
templates *template.Template
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
|
|
|
|
return t.templates.ExecuteTemplate(w, name, data)
|
|
|
|
}
|
2024-09-18 19:06:33 -04:00
|
|
|
|
|
|
|
// NewTemplate returns a new Template instance with templates embedded from *.html
|
|
|
|
func NewTemplate() *Template {
|
|
|
|
return &Template{
|
|
|
|
templates: template.Must(template.ParseFS(templatesFS, "*.html")),
|
|
|
|
}
|
|
|
|
}
|