JetRenderer | Jet |
---|---|
v1 |
v5 |
v2 |
v6 |
See example.
package main
import (
"io"
"net/http"
"strings"
"github.com/CloudyKit/jet/v6"
"clevergo.tech/clevergo"
"clevergo.tech/jetrenderer"
)
func main() {
renderer := jetrenderer.New(jet.New(jet.NewOSFileSystemLoader("./views")))
renderer.SetBeforeRender(func(w io.Writer, name string, vars jet.VarMap, data interface{}, ctx *clevergo.Context) error {
// populate variables and functions
// vars.Set("user", user) // user instance.
// vars.SetFunc("T", translate) // i18n translator.
return nil
})
app := clevergo.New()
app.Renderer = renderer
app.Get("/", func(ctx *clevergo.Context) error {
return ctx.Render(http.StatusOK, "index.tmpl", map[string]interface{}{
"message": "hello world",
})
})
app.Run(":8080")
}