add support for pongo2.TemplateLoader
This commit is contained in:
parent
c562e32f91
commit
1977a5f4ff
12
README.md
12
README.md
@ -1,3 +1,9 @@
|
||||
# pongo2 for gin
|
||||
|
||||
github.com/flosch/pongo2 master branch is used.
|
||||
|
||||
If you'd like to use pongo2.v3 see github.com/dalu/pongo2v3
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
@ -11,12 +17,12 @@
|
||||
func main () {
|
||||
r := gin.Default()
|
||||
|
||||
pr := ginpongo2.New("templates", gin.IsDebugging())
|
||||
// default is the TemplateSet name
|
||||
// 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())
|
||||
|
||||
ginpongo2.Suffix = ".html.twig" // this is default
|
||||
// when ever you render something reference it by prefix
|
||||
// e.g. frontpage = frontpage.html.twig
|
||||
@ -33,3 +39,5 @@
|
||||
r.Run(":8080")
|
||||
}
|
||||
```
|
||||
|
||||
You can also supply TemplateLoaders. See [pongo2.TemplateLoader](https://pkg.go.dev/github.com/flosch/pongo2?tab=doc#TemplateLoader) documentation. It allows you to for example embed resources from a virtual filesystem.
|
@ -46,7 +46,7 @@ func (r *PongoRenderer) WriteContentType(w http.ResponseWriter) {
|
||||
}
|
||||
}
|
||||
|
||||
func New(basedir string, debug bool) *Pongo {
|
||||
func New(basedir string, debug bool, loaders ...pongo2.TemplateLoader) *Pongo {
|
||||
p := new(Pongo)
|
||||
p.set = pongo2.NewSet("html")
|
||||
p.set.Debug = debug
|
||||
@ -54,5 +54,8 @@ func New(basedir string, debug bool) *Pongo {
|
||||
basedir = basedir + "/"
|
||||
}
|
||||
p.basedir = basedir
|
||||
if len(loaders) > 0 {
|
||||
p.set.AddLoader(loaders...)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user