templating

package
v0.0.43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine is a template engine based on template.Template with some additional functions. Don't create objects of this type directly, use the NewConsole function instead.

func (*Engine) AddFS

func (e *Engine) AddFS(values ...fs.FS) error

AddFS adds one or more filesystems to the engine and loads templates from them. This can be called after the engine has been created to add additional template sources.

func (*Engine) Execute

func (e *Engine) Execute(writer io.Writer, name string, data any) error

Execute executes the template with the given name and passing the given input data. It writes the result to the given writer.

func (*Engine) Names

func (e *Engine) Names() []string

Names returns the names of the templates.

type EngineBuilder

type EngineBuilder struct {
	// contains filtered or unexported fields
}

EngineBuilder contains the data and logic needed to create templates. Don't create objects of this type directly, use the NewEngine function instead.

func NewEngine

func NewEngine() *EngineBuilder

NewEngine creates a builder that can the be used to create a template engine.

func (*EngineBuilder) AddFS

func (b *EngineBuilder) AddFS(values ...fs.FS) *EngineBuilder

AddFS adds one or more filesystems that will be used to read the templates. At least one filesystem must be added before building the engine.

func (*EngineBuilder) AddFunction

func (b *EngineBuilder) AddFunction(name string, function any) *EngineBuilder

AddFunction adds a custom function that will be available to the templates. This is optional. The function can be used in templates with the given name.

func (*EngineBuilder) AddFunctions

func (b *EngineBuilder) AddFunctions(functions tmpl.FuncMap) *EngineBuilder

AddFunctions adds multiple custom functions that will be available to the templates. This is optional. The functions can be used in templates with the names specified in the map keys.

func (*EngineBuilder) Build

func (b *EngineBuilder) Build() (result *Engine, err error)

Build uses the configuration stored in the builder to create a new engine.

func (*EngineBuilder) SetDir

func (b *EngineBuilder) SetDir(value string) *EngineBuilder

SetDir instructs the engine to load load the templates only from the given directory of the filesystem. This is optional and the default is to load all the templates.

func (*EngineBuilder) SetLogger

func (b *EngineBuilder) SetLogger(value *slog.Logger) *EngineBuilder

SetLogger sets the logger that the engine will use to write messages to the log. This is mandatory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL