Documentation
¶
Index ¶
- func Compile(options CompileOptions) (*template.Template, error)
- type CompileOptions
- type Delims
- type ServiceProvider
- type Template
- type View
- func (r *View) AddFuncs(funcs template.FuncMap)
- func (r *View) Exists(view string) bool
- func (r *View) First(views []string, data ...any) contractsview.Template
- func (r *View) Funcs() template.FuncMap
- func (r *View) GetShared() map[string]any
- func (r *View) LoadViewsFrom(path string)
- func (r *View) LoadViewsFromFS(fsys fs.FS, root string)
- func (r *View) Make(view string, data ...any) contractsview.Template
- func (r *View) RegisteredViewFS() []fs.FS
- func (r *View) RegisteredViews() []string
- func (r *View) Share(key string, value any)
- func (r *View) Shared(key string, def ...any) any
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compile ¶
func Compile(options CompileOptions) (*template.Template, error)
Compile parses the application's resources/views directory and every package source in options into one template set, in precedence order: application views first, then options.Paths, then options.FS, each in the order given.
Every file is parsed under its slash-separated path relative to its source root, and additionally under the name of its {{ define }} block when it has one. A name already taken by a higher-precedence source causes the whole file to be skipped: silently when the application owns the name, with a warning when another package does. Route drivers wrap the returned set in their own renderer type.
Compile returns (nil, nil) when no source contributed a file.
Types ¶
type CompileOptions ¶
type CompileOptions struct {
// Delims replaces the default "{{" and "}}" action delimiters.
Delims *Delims
// FuncMap is installed on the template set before any file is parsed.
FuncMap template.FuncMap
// Paths are package view directories in precedence order, typically
// View.RegisteredViews(). A path that is missing or not a directory is skipped.
Paths []string
// FS are package view filesystems in precedence order, typically
// View.RegisteredViewFS(). A nil or unreadable filesystem is skipped with a warning.
FS []fs.FS
// Extensions limits parsing to files with one of these extensions, dot
// included. Empty parses every file.
Extensions []string
// Log receives warnings about name collisions and skipped filesystems. nil
// silences them.
Log contractslog.Log
}
CompileOptions configures Compile.
type ServiceProvider ¶
type ServiceProvider struct{}
func (*ServiceProvider) Boot ¶
func (r *ServiceProvider) Boot(app foundation.Application)
func (*ServiceProvider) Register ¶
func (r *ServiceProvider) Register(app foundation.Application)
func (*ServiceProvider) Relationship ¶
func (r *ServiceProvider) Relationship() contractsbinding.Relationship
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template is a view bound to its data. Data that cannot be rendered, and a First that matched nothing, are reported by Render rather than when the template is built.
type View ¶
type View struct {
// contains filtered or unexported fields
}
func (*View) AddFuncs ¶
AddFuncs merges funcs into the registry. A later registration overrides an earlier one with the same name, so the application's functions, which the framework adds after every provider has booted, win over package functions.
func (*View) Exists ¶
Exists reports whether a view file with the given name is available from any source. Only files count: directories, "" and "." (which would resolve to a source root) do not match.
func (*View) First ¶
func (r *View) First(views []string, data ...any) contractsview.Template
First returns a template for the first view in the list that can be rendered.
func (*View) Funcs ¶
Funcs returns a copy of the registered functions, so callers may hand it to html/template.Funcs without affecting later registrations.
func (*View) LoadViewsFrom ¶
func (*View) Make ¶
func (r *View) Make(view string, data ...any) contractsview.Template
Make returns a template for the view, bound to the given data.