template

GitHub Workflow Status Codecov GoDoc Sourcegraph

Package template is a middleware that provides Go template rendering for Flamego.

Installation

The minimum requirement of Go is 1.16.

  1. go get github.com/flamego/template

Getting started

  1. <!-- templates/home.tmpl -->
  2. <p>
  3. Hello, <b>{{.Name}}</b>!
  4. </p>
  1. package main
  2. import (
  3. "http"
  4. "github.com/flamego/flamego"
  5. "github.com/flamego/template"
  6. )
  7. func main() {
  8. f := flamego.Classic()
  9. f.Use(template.Templater())
  10. f.Get("/", func(t template.Template, data template.Data) {
  11. data["Name"] = "Joe"
  12. t.HTML(http.StatusOK, "home")
  13. })
  14. f.Run()
  15. }

Getting help

License

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