1.3 KiB
1.3 KiB
pongo2.v3 for go-gin
- using templatesets
- debug aware
- basepath suppliable
How to use
main.go
package main
import (
"github.com/gin-gonic/gin"
"github.com/dalu/ginpongo2v3"
"gopkg.in/flosch/pongo2.v3"
)
func main () {
r := gin.Default()
pr := ginpongo2v3.New("default", "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.
ginpongo2v3.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")
}
templates/frontpage.html.twig
{{greeting}}
hello world