if no loader present provide default

This commit is contained in:
Darko Luketic 2020-03-19 21:56:28 +01:00
parent 1977a5f4ff
commit 05e3020554

View File

@ -13,12 +13,11 @@ var Suffix = ".html.twig"
type Pongo struct { type Pongo struct {
set *pongo2.TemplateSet set *pongo2.TemplateSet
basedir string
} }
func (p *Pongo) Instance(name string, data interface{}) render.Render { func (p *Pongo) Instance(name string, data interface{}) render.Render {
r := new(PongoRenderer) r := new(PongoRenderer)
tpl, e := p.set.FromCache(fmt.Sprintf("%s%s%s", p.basedir, name, Suffix)) tpl, e := p.set.FromCache(fmt.Sprintf("%s%s", name, Suffix))
if e != nil { if e != nil {
panic(e) panic(e)
} }
@ -53,9 +52,10 @@ func New(basedir string, debug bool, loaders ...pongo2.TemplateLoader) *Pongo {
if !strings.HasSuffix(basedir, "/") { if !strings.HasSuffix(basedir, "/") {
basedir = basedir + "/" basedir = basedir + "/"
} }
p.basedir = basedir
if len(loaders) > 0 { if len(loaders) > 0 {
p.set.AddLoader(loaders...) p.set.AddLoader(loaders...)
} else {
p.set.AddLoader(pongo2.MustNewLocalFileSystemLoader(basedir))
} }
return p return p
} }