Documentation
¶
Index ¶
- Variables
- type Delims
- type FuncMap
- type HTMLTemplates
- func (ht *HTMLTemplates) Delims(left, right string)
- func (ht *HTMLTemplates) Extensions(extensions ...string)
- func (ht *HTMLTemplates) Funcs(funcMap FuncMap)
- func (ht *HTMLTemplates) Load(root string) (err error)
- func (ht *HTMLTemplates) LoadFS(fsys fs.FS, root string) (err error)
- func (ht *HTMLTemplates) Render(w io.Writer, locale, name string, data any) error
- type Templates
- type TextTemplates
- func (tt *TextTemplates) Delims(left, right string)
- func (tt *TextTemplates) Extensions(extensions ...string)
- func (tt *TextTemplates) Funcs(funcMap FuncMap)
- func (tt *TextTemplates) Load(root string) (err error)
- func (tt *TextTemplates) LoadFS(fsys fs.FS, root string) (err error)
- func (tt *TextTemplates) Render(w io.Writer, locale, name string, data any) error
Constants ¶
This section is empty.
Variables ¶
var HTMLTemplateExtensions = []string{".tpl", ".html", ".gohtml"}
var TextTemplateExtensions = []string{".tpl", ".txt", ".gotxt"}
Functions ¶
This section is empty.
Types ¶
type FuncMap ¶
FuncMap is the type of the map defining the mapping from names to functions. Each function must have either a single return value, or two return values of which the second has type error. In that case, if the second (error) argument evaluates to non-nil during execution, execution terminates and Execute returns that error. FuncMap has the same base type as FuncMap in "text/template", copied here so clients need not import "text/template".
type HTMLTemplates ¶
type HTMLTemplates struct {
// contains filtered or unexported fields
}
HTMLTemplates html template engine
func NewHTMLTemplates ¶
func NewHTMLTemplates(extensions ...string) *HTMLTemplates
NewHTMLTemplates new template engine
func (*HTMLTemplates) Delims ¶
func (ht *HTMLTemplates) Delims(left, right string)
Delims sets template left and right delims and returns a Engine instance.
func (*HTMLTemplates) Extensions ¶
func (ht *HTMLTemplates) Extensions(extensions ...string)
Extensions sets template entensions.
func (*HTMLTemplates) Funcs ¶
func (ht *HTMLTemplates) Funcs(funcMap FuncMap)
Funcs sets the FuncMap used for template.FuncMap.
func (*HTMLTemplates) Load ¶
func (ht *HTMLTemplates) Load(root string) (err error)
Load glob and parse template files under the root path
func (*HTMLTemplates) LoadFS ¶
func (ht *HTMLTemplates) LoadFS(fsys fs.FS, root string) (err error)
LoadFS glob and parse template files from FS
type Templates ¶
type Templates interface {
// Extensions sets template entensions.
Extensions(extensions ...string)
// Delims sets template left and right delims and returns a Engine instance.
Delims(left, right string)
// Funcs sets the FuncMap used for template.FuncMap.
Funcs(funcMap FuncMap)
// Load glob and parse template files under the root path
Load(root string) error
// LoadFS glob and parse template files from FS
LoadFS(fsys fs.FS, root string) error
// Render render template with io.Writer
// If locale is not empty, it will try to load locale template first.
// For example, if locale is "zh-TW" and name is "hello", it will try to load template via the following order.
// 1. "hello.zh-TW.tpl"
// 2. "hello.zh.tpl"
// 3. "hello.tpl"
Render(w io.Writer, locale, name string, data any) error
}
Templates templates interface
type TextTemplates ¶
type TextTemplates struct {
// contains filtered or unexported fields
}
TextTemplates text template engine
func NewTextTemplates ¶
func NewTextTemplates(extensions ...string) *TextTemplates
NewTextTemplates new templates instance
func (*TextTemplates) Delims ¶
func (tt *TextTemplates) Delims(left, right string)
Delims sets template left and right delims and returns a Engine instance.
func (*TextTemplates) Extensions ¶
func (tt *TextTemplates) Extensions(extensions ...string)
Extensions sets template entensions.
func (*TextTemplates) Funcs ¶
func (tt *TextTemplates) Funcs(funcMap FuncMap)
Funcs sets the FuncMap used for template.FuncMap.
func (*TextTemplates) Load ¶
func (tt *TextTemplates) Load(root string) (err error)
Load glob and parse template files under the root path
func (*TextTemplates) LoadFS ¶
func (tt *TextTemplates) LoadFS(fsys fs.FS, root string) (err error)
LoadFS glob and parse template files from FS