mercury/web/templates/templates.go

29 lines
500 B
Go
Raw Normal View History

2023-09-03 04:11:56 +02:00
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
}