2017-10-03 21:43:55 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gin-contrib/multitemplate"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2018-04-22 14:51:19 +03:00
|
|
|
func createMyRender() multitemplate.Renderer {
|
|
|
|
r := multitemplate.NewRenderer()
|
2017-10-03 21:43:55 +03:00
|
|
|
r.AddFromFiles("index", "templates/base.html", "templates/index.html")
|
|
|
|
r.AddFromFiles("article", "templates/base.html", "templates/index.html", "templates/article.html")
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
router := gin.Default()
|
|
|
|
router.HTMLRender = createMyRender()
|
|
|
|
router.GET("/", func(c *gin.Context) {
|
|
|
|
c.HTML(200, "index", gin.H{
|
|
|
|
"title": "Html5 Template Engine",
|
|
|
|
})
|
|
|
|
})
|
|
|
|
router.GET("/article", func(c *gin.Context) {
|
|
|
|
c.HTML(200, "article", gin.H{
|
|
|
|
"title": "Html5 Article Engine",
|
|
|
|
})
|
|
|
|
})
|
|
|
|
router.Run(":8080")
|
|
|
|
}
|