loader(s) must be passed on initialization
This commit is contained in:
parent
05e3020554
commit
135199c774
@ -17,11 +17,13 @@ If you'd like to use pongo2.v3 see github.com/dalu/pongo2v3
|
||||
func main () {
|
||||
r := gin.Default()
|
||||
|
||||
pl := pongo2.MustNewLocalFileSystemLoader("templates")
|
||||
|
||||
// templates is the basePath
|
||||
// gin.IsDebugging() means if gin is in debug/dev mode then templates
|
||||
// will always be reloaded from disk, otherwise from cache and never
|
||||
// reloaded.
|
||||
pr := ginpongo2.New("templates", gin.IsDebugging())
|
||||
pr := ginpongo2.New(gin.IsDebugging(), pl)
|
||||
|
||||
ginpongo2.Suffix = ".html.twig" // this is default
|
||||
// when ever you render something reference it by prefix
|
||||
|
16
render.go
16
render.go
@ -2,11 +2,9 @@ package ginpongo2
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/flosch/pongo2"
|
||||
"github.com/gin-gonic/gin/render"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var Suffix = ".html.twig"
|
||||
@ -45,17 +43,9 @@ func (r *PongoRenderer) WriteContentType(w http.ResponseWriter) {
|
||||
}
|
||||
}
|
||||
|
||||
func New(basedir string, debug bool, loaders ...pongo2.TemplateLoader) *Pongo {
|
||||
func New(debug bool, loaders ...pongo2.TemplateLoader) *Pongo {
|
||||
p := new(Pongo)
|
||||
p.set = pongo2.NewSet("html")
|
||||
p.set = pongo2.NewSet("html", loaders...)
|
||||
p.set.Debug = debug
|
||||
if !strings.HasSuffix(basedir, "/") {
|
||||
basedir = basedir + "/"
|
||||
}
|
||||
if len(loaders) > 0 {
|
||||
p.set.AddLoader(loaders...)
|
||||
} else {
|
||||
p.set.AddLoader(pongo2.MustNewLocalFileSystemLoader(basedir))
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user