Skip to content

clevergo/jetrenderer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Renderer implementation of Jet template engine

Build Status Coverage Status Go.Dev reference Go Report Card Release Downloads Chat Community

JetRenderer Jet
v1 v5
v2 v6

Usage

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")
}