tpl

package
v0.0.0-...-432eb6a Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bundle

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

Bundle represents a collection of templates that extend a shared base.

func NewBundle

func NewBundle(viewsDir string, sharedDirs []string, opts ...Option) (*Bundle, error)

NewBundle creates a new bundle of templates with the given options.

The viewsDir is a glob pattern for templates considered to be primary pages (e.g., "views/*.html"). The sharedDirs are glob patterns for shared component templates.

func (*Bundle) HasTemplate

func (b *Bundle) HasTemplate(name string) bool

HasTemplate checks if a template with the given name exists.

func (*Bundle) Render

func (b *Bundle) Render(w http.ResponseWriter, name string, data Data) error

Render renders the named template with the given data to the http.ResponseWriter.

func (*Bundle) TemplateNames

func (b *Bundle) TemplateNames() []string

TemplateNames returns a list of all registered template names.

func (*Bundle) Validate

func (b *Bundle) Validate() error

Validate checks that all templates can be executed without errors.

type Data

type Data map[string]any

Data represents the data to be rendered for a template.

type Option

type Option func(*Bundle) error

Option is a functional option for configuring a Bundle.

func WithBaseTpl

func WithBaseTpl(name string) Option

WithBaseTpl sets the base template name that other templates extend.

func WithFuncs

func WithFuncs(funcMap template.FuncMap) Option

WithFuncs adds custom template functions.

Jump to

Keyboard shortcuts

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