gin-template
gin-template copied to clipboard
Multiple template problem
Hi
i have a login page and dont want use master page but other pages can be use master page.
i set .HTMLRender = gintemplate.New(gintemplate.TemplateConfig{ Root: "views", Extension: ".html", Master: "layouts/master", Partials: []string{}, Funcs: template.FuncMap{ "copy": func() string { return time.Now().Format("2018") }, }, DisableCache: isDebugMode, })
but my application start with login page set empty temlate config but give an error. it wants to use master page can you help me ?
emptyMasterPage := gintemplate.NewMiddleware(gintemplate.TemplateConfig{
Root: "views",
Extension: ".html",
Master: "",
Partials: []string{},
DisableCache: true,
})
server.Engine().GET("/", func(ctx *gin.Context) {
// With the middleware, `HTML()` can detect the valid TemplateEngine.
gintemplate.HTML(ctx, http.StatusOK, "account/login", gin.H{
"title": "Backend title!",
})
}, server.EmptyMasterPage())
If you have a login page and dont want use master, you render name add ".html", like this:
gintemplate.HTML(ctx, http.StatusOK, "account/login.html", gin.H{
"title": "Backend title!",
})
- "account/login.html" - Not render with master
- "account/login" - Render with master
Please see examples: https://github.com/foolin/echo-template/tree/master/examples/basic
index.html is use master, but page.html is not.