Documentation
¶
Overview ¶
Package render provides html/templates rendering for the composable templates which can be called a set of templates.
// we define some layout/desktop.html
{{ template "header" .}}
{{ template "content" .}}
// then in the common/header.html, we define
{{ define "header" }} ... {{ end }}
// then we define content inside some index.html
{{ define "content" }}<p>Hello {{ .Hello }}</p>{{ end }}
// we can link those fragments as a render.TemplateSet
ts := render.TemplateSet("index", "desktop.html", "common/header.html", "index.html", "layout/desktop.html")
// New a renderer with some options
r := render.New(render.Options{
Directory: "templates",
Funcs: []template.FuncMap{someServer.DefaultRouteFuncs()},
Delims: render.Delims{"{{", "}}"},
IndentJson: true,
UseBufPool: true,
IsDevelopment: false,
}, []*render.TemplateSet{ts})
// e.g. render some named templates
err := r.Html(w, http.StatusOK, "index", map[string]string{ "Hello": "World" })
// or we can render some json data
err := r.Json(w, http.StatusOK, "Hello World")
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Templates lookup directory
Directory string
// User defined functions passed to the template engine
Funcs []template.FuncMap
// Deliminator for the html/template
Delims Delims
// Should indent json for readable format when call r.Json
IndentJson bool
// Should use the buf pool for the rendering or just use the bytes.Buffer
UseBufPool bool
// In development mode, the templates would be recompiled for each rendering call
IsDevelopment bool
}
Options defines basic options for the renderer.
type Render ¶
type Render struct {
// contains filtered or unexported fields
}
Render defines basic renderer data.
func New ¶
func New(opt Options, tSets []*TemplateSet) *Render
New a renderer with given template sets and options.
type TemplateSet ¶
type TemplateSet struct {
// contains filtered or unexported fields
}
TemplateSet defines a template set for composable template fragments
func NewTemplateSet ¶
func NewTemplateSet(name string, entry string, tFile string, otherFiles ...string) *TemplateSet
NewTemplateSet returns a new template set, name provides the name for reverse searching, entry defines the most top template name, like the "layout.html"; have to at least give a template file or multiple template files used in this set.
Click to show internal directories.
Click to hide internal directories.