renders is go template middleware for tango
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lunny Xiao 78fc56203e
fix test
1 month ago
templates Added RenderBytes for Renderer and simplifed codes. 4 years ago
.drone.yml use go mod & add drone 6 months ago
.gitignore fix test 1 month ago
LICENSE license 4 years ago
README.md use go mod & add drone 6 months ago
circle.yml update CI config 2 years ago
funcs.go bug fixed for go-xorm/xorm#7 3 years ago
go.mod use go mod & add drone 6 months ago
go.sum update go.sum 1 month ago
loader.go better error information when template is missing 6 months ago
options.go add http.FileSystem support and refactors 2 years ago
renders.go migrate to gitea.com/lunny/tango 8 months ago
renders_test.go fix test 1 month ago

README.md

renders Build Status

Middleware renders is a go template render middlewaer for Tango.

Version

v0.2.0510 Added RenderBytes for Renderer and simplifed codes.

Installation

go get gitea.com/tango/renders

Simple Example

type RenderAction struct {
    renders.Renderer
}

func (x *RenderAction) Get() {
    x.Render("test.html", renders.T{
        "test": "test",
    })
}

func main() {
    t := tango.Classic()
    t.Use(renders.New(renders.Options{
        Reload: true, // if reload when template is changed
        Directory: "./templates", // Directory to load templates
        Funcs: template.FuncMap{
            "test": func() string {
                    return "test"
            },
        },
        // Vars is a data map for global
        Vars: renders.T{
            "var": var,
        }
        Charset: "UTF-8", // Appends the given charset to the Content-Type header. Default is UTF-8
        // Allows changing of output to XHTML instead of HTML. Default is "text/html"
        HTMLContentType: "text/html",
        DelimsLeft:"{{",
        DelimsRight:"}}", // default Delims is {{}}, if it conflicts with your javascript template such as angluar, you can change it.
    }))
}

License

This project is under BSD License. See the LICENSE file for the full license text.