Documentation
¶
Index ¶
- type Entemplate
- func (x *Entemplate) AutoReload(reload bool) *Entemplate
- func (x *Entemplate) Delims(left, right string) *Entemplate
- func (x *Entemplate) ExecuteTemplate(wr io.Writer, name string, data ...interface{}) error
- func (x *Entemplate) Funcs(funcMap template.FuncMap) *Entemplate
- func (x *Entemplate) Lookup(name string) *template.Template
- func (x *Entemplate) ParseDir(root string, extensions []string) error
- func (x *Entemplate) ParseFS(tplFs fs.FS, root string, extensions []string) error
- func (x *Entemplate) Templates() map[string]*template.Template
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entemplate ¶
type Entemplate struct {
// contains filtered or unexported fields
}
Entemplate holds a reference to all templates and shared configuration like Delims or FuncMap
func (*Entemplate) AutoReload ¶
func (x *Entemplate) AutoReload(reload bool) *Entemplate
AutoReload configures whether the templates will be automatically reloaded from disk when they change. This setting has no effect when static templates are compiled into the source.
func (*Entemplate) Delims ¶
func (x *Entemplate) Delims(left, right string) *Entemplate
Delims sets the action delimiters to the specified strings, to be used in subsequent calls to ParseDir. Nested template definitions will inherit the settings. An empty delimiter stands for the corresponding default: {{ or }}. The return value is the template, so calls can be chained.
func (*Entemplate) ExecuteTemplate ¶
func (x *Entemplate) ExecuteTemplate(wr io.Writer, name string, data ...interface{}) error
ExecuteTemplate applies the template named name to the specified data object and writes the output to wr. Templates will be automatically reloaded if AutoReload is true. In addition to handling a single data object as is done in the standard library, this wrapper also supports providing key/value pairs as individual arguments. e.g.
tpl.ExecuteTemplate(w, "template.html", "name", "Bob", "age", 42)
func (*Entemplate) Funcs ¶
func (x *Entemplate) Funcs(funcMap template.FuncMap) *Entemplate
Funcs adds the elements of the argument map to the template's function map. It must be called before templates are parsed It panics if a value in the map is not a function with appropriate return type or if the name cannot be used syntactically as a function in a template. It is legal to overwrite elements of the map. The return value is the Entemplate instance, so calls can be chained.
func (*Entemplate) Lookup ¶
func (x *Entemplate) Lookup(name string) *template.Template
Lookup returns the template with the given name It returns nil if there is no such template or the template has no definition.
func (*Entemplate) ParseDir ¶
func (x *Entemplate) ParseDir(root string, extensions []string) error
ParseDir walks the given directory root and parses all files with any of the registered extensions. Default extensions are .html and .tmpl If a template file has {{/* extends "other-file.tmpl" */}} as its first line it will parse that file for base templates. Parsed templates are named relative to the given root directory