node-api/templates.go

30 lines
551 B
Go
Raw Normal View History

2020-07-13 22:01:42 +00:00
package main
import (
"html/template"
"io"
"github.com/gobuffalo/packr"
"github.com/labstack/echo"
)
// Template struct
type Template struct{}
// Render template saved in packr
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
box := packr.NewBox("./ui")
tmpl, err := template.New(name).Parse(box.String("index.html"))
if err != nil {
panic(err)
}
tmpl, err = tmpl.Parse(box.String(name))
if err != nil {
panic(err)
}
response := tmpl.ExecuteTemplate(w, name, data)
return response
}