From 1977a5f4ff492f22fbded00c61de298624293fcb Mon Sep 17 00:00:00 2001 From: Darko Luketic <2694548+dalu@users.noreply.github.com> Date: Thu, 19 Mar 2020 21:10:06 +0100 Subject: [PATCH] add support for pongo2.TemplateLoader --- README.md | 14 +++++++++++--- render.go | 5 ++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6904d84..4dff241 100644 --- a/README.md +++ b/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 @@ -32,4 +38,6 @@ r.Run(":8080") } -``` \ No newline at end of file +``` + +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. \ No newline at end of file diff --git a/render.go b/render.go index c59d1fb..ebd9595 100644 --- a/render.go +++ b/render.go @@ -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 }