Documentation ¶
Overview ¶
Package GinHTMLRender provides some sugar for gin's template rendering
This work is based on gin contribs multitemplate render https://github.com/gin-gonic/contrib/blob/master/renders/multitemplate
Usage
router := gin.Default() // Set html render options htmlRender := GinHTMLRender.New() htmlRender.Debug = gin.IsDebugging() htmlRender.Layout = "layouts/default" // htmlRender.TemplatesDir = "templates/" // default // htmlRender.Ext = ".html" // default // Tell gin to use our html render router.HTMLRender = htmlRender.Create()
Structure
|-- templates/ |-- |-- 400.html |-- 404.html |-- layouts/ |--- default.html |-- articles/ |--- list.html |--- form.html
And if you want to render `templates/articles/list.html` in your handler
c.HTML(http.StatusOK, "articles/list", "")
Index ¶
Constants ¶
View Source
const ( // TemplatesDir holds the location of the templates TemplatesDir = "templates/" // Layout is the file name of the layout file Layout = "layout" // Ext is the file extension of the rendered templates Ext = ".html" // Debug enables debug mode Debug = false )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Render ¶
type Render struct { Templates map[string]*template.Template Files map[string][]string TemplatesDir string Layout string Ext string Debug bool }
Render implements gin's HTMLRender and provides some sugar on top of it
func (*Render) AddFromFiles ¶
AddFromFiles parses the files and returns the result
func (*Render) Create ¶
Create goes through the `TemplatesDir` creating the template structure for rendering. Returns the Render instance.
Click to show internal directories.
Click to hide internal directories.