mercury/web/templates/templates.go

28 lines
500 B
Go

package templates
import (
"embed"
"emperror.dev/errors"
"github.com/flosch/pongo2/v6"
)
//go:embed *
var fs embed.FS
func New(dev bool) (*pongo2.TemplateSet, error) {
if dev {
loader, err := pongo2.NewLocalFileSystemLoader("web/templates")
if err != nil {
return nil, errors.Wrap(err, "creating filesystem loader")
}
ts := pongo2.NewSet("web", loader)
ts.Debug = true
return ts, nil
}
loader := pongo2.NewFSLoader(fs)
ts := pongo2.NewSet("web", loader)
return ts, nil
}