https://github.com/night-codes/go-gin-ttpl
Custom render for gin-gonic by "text/template" instead "html/template"
https://github.com/night-codes/go-gin-ttpl
Last synced: 6 months ago
JSON representation
Custom render for gin-gonic by "text/template" instead "html/template"
- Host: GitHub
- URL: https://github.com/night-codes/go-gin-ttpl
- Owner: night-codes
- License: wtfpl
- Created: 2016-02-22T05:03:03.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-08-14T12:21:43.000Z (almost 7 years ago)
- Last Synced: 2024-06-20T05:09:15.894Z (12 months ago)
- Language: Go
- Size: 3.91 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-gin-ttpl
Custom render for gin-gonic by "text/template" instead "html/template"## Why Do It?
Sometimes we need to render templates without HTML. Also "html/template" has the [problem](https://github.com/golang/go/issues/12149) with parser.## How To Use
```go
package mainimport (
"gopkg.in/gin-gonic/gin.v1"
"gopkg.in/night-codes/go-gin-ttpl.v1"
)func main() {
r := gin.New()
ttpl.Use(r, "templates/*")
r.GET("/", func(c *gin.Context) {
c.HTML(200, "index.html", gin.H{"title": "top"})
})
r.Run(":41000")
}
```When you want to add your own template functions you can pass a third parameter - FuncMap
```go
import (
// ...
"text/template"
)func main() {
// ...
funcMap := template.FuncMap{
"customFunc": customFunc, // A custom template function
}
ttpl.Use(r, "templates/*", funcMap) // <--
// ...
}
```## License
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004Copyright (C) 2015 Oleksiy Chechel
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION0. You just DO WHAT THE FUCK YOU WANT TO.