Add Template layouts, load session hashkey

This commit is contained in:
Wancat
2022-11-04 22:44:25 +08:00
parent bc1095fc61
commit bca1735393
7 changed files with 77 additions and 38 deletions

View File

@@ -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)
}