templates

package
v0.1.31 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

templates/adapter.go

templates/engine.go

templates/funcs.go

templates/views.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Funcs

func Funcs() template.FuncMap

Funcs returns helpers available to all templates.

func Register

func Register(s Set)

Register is typically called from a feature package’s init(). It records a template Set so the Engine can load it at Boot().

func Render

func Render(w http.ResponseWriter, r *http.Request, name string, data any)

Render executes a full page (entry template that calls layout).

func RenderAuto

func RenderAuto(w http.ResponseWriter, r *http.Request, page, tableSnippet, targetID string, data any)

Convenience for the common single-table swap case.

func RenderAutoMap

func RenderAutoMap(w http.ResponseWriter, r *http.Request, page string, targets map[string]string, data any)

RenderAutoMap picks a snippet based on HX-Target; if HX-Target is "content", it renders the page's content-only block. Otherwise it renders the full page.

func RenderSnippet

func RenderSnippet(w http.ResponseWriter, name string, data any)

RenderSnippet executes a partial by name (e.g., "groups_table").

func Reset

func Reset()

Reset is handy for tests.

func UseEngine

func UseEngine(e *Engine, l *zap.Logger)

UseEngine installs the engine and logger used by the helper Render functions.

Types

type Engine

type Engine struct {
	Logger *zap.Logger
	// contains filtered or unexported fields
}

Engine compiles and holds templates from all registered Sets. It supports a "shared" set (common layout) and per-page clones.

func New

func New(dev bool) *Engine

New creates a new Engine. dev=true can be used later to support hot-reload.

func (*Engine) Boot

func (e *Engine) Boot(logger *zap.Logger) error

Boot compiles all registered template Sets into the Engine. It must be called before Render/RenderSnippet, typically at startup.

func (*Engine) Render

func (e *Engine) Render(w Writer, r Request, name string, data any) error

Render executes a top-level template by name using this engine. Usually you’ll call the package-level Render helpers in adapter.go.

func (*Engine) RenderContent

func (e *Engine) RenderContent(w Writer, entry string, data any) error

RenderContent executes the "content" block associated with the given entry template.

func (*Engine) RenderSnippet

func (e *Engine) RenderSnippet(w Writer, name string, data any) error

RenderSnippet executes a partial template by name (e.g., a table or fragment).

type Request

type Request interface{}

type Set

type Set struct {
	// Name is for logging / debugging only (e.g., "shared", "admin_resources").
	Name string
	// FS is the embedded filesystem from the feature package.
	FS fs.FS
	// Patterns are the glob patterns to load from FS (e.g., []string{"templates/*.gohtml"}).
	Patterns []string
}

Set describes one module's template set.

func All

func All() []Set

All returns the registered template sets. The Engine calls this once at Boot.

type Writer

type Writer interface{ Write([]byte) (int, error) }

Writer and Request interfaces let us avoid importing net/http here.

Jump to

Keyboard shortcuts

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