当前位置: 首页>>代码示例>>Golang>>正文


Golang Engine.SetHTMLTemplate方法代码示例

本文整理汇总了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)
}
开发者ID:denisbakhtin,项目名称:ginblog,代码行数:29,代码来源:main.go

示例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)
}
开发者ID:goodplayer,项目名称:Princess,代码行数:12,代码来源:route.go

示例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(""))
}
开发者ID:wangmingjob,项目名称:goyangi,代码行数:18,代码来源:index.go


注:本文中的github.com/gin-gonic/gin.Engine.SetHTMLTemplate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。