本文整理汇总了Golang中github.com/gin-gonic/gin.Engine.SetHTMLTemplate方法的典型用法代码示例。如果您正苦于以下问题:Golang Engine.SetHTMLTemplate方法的具体用法?Golang Engine.SetHTMLTemplate怎么用?Golang Engine.SetHTMLTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/gin-gonic/gin.Engine
的用法示例。
在下文中一共展示了Engine.SetHTMLTemplate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: setTemplate
//setTemplate loads templates from rice box "views"
func setTemplate(router *gin.Engine) {
box := rice.MustFindBox("views")
tmpl := template.New("").Funcs(template.FuncMap{
"isActive": helpers.IsActive,
"stringInSlice": helpers.StringInSlice,
"dateTime": helpers.DateTime,
"recentPosts": helpers.RecentPosts,
"tags": helpers.Tags,
"archives": helpers.Archives,
})
fn := func(path string, f os.FileInfo, err error) error {
if f.IsDir() != true && strings.HasSuffix(f.Name(), ".html") {
var err error
tmpl, err = tmpl.Parse(box.MustString(path))
if err != nil {
return err
}
}
return nil
}
err := box.Walk("", fn)
if err != nil {
panic(err)
}
router.SetHTMLTemplate(tmpl)
}
示例2: loadHTMLGlob
//TODO customize templates
func loadHTMLGlob(r *gin.Engine, pattern string, templFunc func(*template.Template)) {
if gin.IsDebugging() {
if len(pattern) <= 0 {
panic("the HTML debug render was created without files or glob pattern")
}
}
templ := template.New("")
templFunc(templ)
templ = template.Must(templ.ParseGlob(pattern))
r.SetHTMLTemplate(templ)
}
示例3: LoadPage
func LoadPage(parentRoute *gin.Engine) {
//type Page struct {
// Title string
//}
parentRoute.SetHTMLTemplate(template.Must(template.ParseFiles("frontend/canjs/templates/message.html", "frontend/canjs/templates/app.html", "frontend/canjs/templates/base.html", "frontend/canjs/templates/404.html")))
log.Debug("url : " + config.StaticUrl)
log.Debug("guid : " + config.Guid)
log.Debug("path : " + staticPath)
parentRoute.Static(config.StaticUrl+"/"+config.Guid, staticPath)
// route.ServeFiles doesn't exist in the current version of gin. If you want to use this, use the 59d949d35080b83864dbeafadecef112d46aaeee.
//parentRoute.ServeFiles(config.StaticUrl+"/"+config.Guid+"/*filepath", http.Dir(staticPath))
parentRoute.NoRoute(func(c *gin.Context) {
c.HTML(404, "404.html", map[string]string{"language": config.DefaultLanguage, "title": config.Title})
})
route.Route(parentRoute.Group(""))
}