Go to file
Darko Luketic 8abf6c96b7 added v6 2022-11-21 14:01:03 +01:00
v4 added v4 2021-11-12 09:26:45 +01:00
v5 added pongo v5 support 2022-04-08 22:14:28 +02:00
v6 added v6 2022-11-21 14:01:03 +01:00
README.md Update 'README.md' 2020-06-17 18:58:13 +02:00
go.mod migration to code.icod.de 2022-10-18 11:50:42 +02:00
go.sum migration to code.icod.de 2022-10-18 11:50:42 +02:00
render.go loader(s) must be passed on initialization 2020-03-19 22:00:14 +01:00

README.md

pongo2 for gin

github.com/flosch/pongo2 master branch is used.

If you'd like to use pongo2.v3 see git.icod.de/dalu/pongo2v3

        package main
        
        import (
         "github.com/gin-gonic/gin"
         "git.icod.de/dalu/ginpongo2"
         "github.com/flosch/pongo2"
        )
        
        
        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(gin.IsDebugging(), pl)
 
    		ginpongo2.Suffix = ".html.twig" // this is default
    		// when ever you render something reference it by prefix
    		// e.g. frontpage = frontpage.html.twig
    		
	    	r.HTMLRender = pr

    		r.GET("/", func(c *gin.Context) {
    			// only pongo2.Context or nil is accepted
	            ctx := make(pongo2.Context)
	            ctx["greeting"] = "hello world"
	            c.HTML(200, "frontpage", ctx)
	            })

    		r.Run(":8080")
        }

You can also supply TemplateLoaders. See pongo2.TemplateLoader documentation. It allows you to for example embed resources from a virtual filesystem.