Add Template layouts, load session hashkey
This commit is contained in:
19
template.go
19
template.go
@@ -5,6 +5,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gin-contrib/multitemplate"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func loadTemplates(templatesDir string) multitemplate.Renderer {
|
||||
@@ -25,3 +26,21 @@ func loadTemplates(templatesDir string) multitemplate.Renderer {
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
type Data interface{}
|
||||
|
||||
type Page struct {
|
||||
Data
|
||||
User UserLogin
|
||||
}
|
||||
|
||||
func HTML(c *gin.Context, status int, name string, data interface{}) {
|
||||
output := Page{
|
||||
Data: data,
|
||||
}
|
||||
_, ok := c.Get("user")
|
||||
if ok {
|
||||
output.User = c.MustGet("user").(UserLogin)
|
||||
}
|
||||
c.HTML(status, name, output)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user