htmltemplate

package
v0.0.0-...-56d8f82 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package htmltemplate provides an HTML renderer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

Middleware

func MustRender

func MustRender(w http.ResponseWriter, req *http.Request, name string, vars ...any)

MustRender is like Render, but panics if an error occurs.

func Render

func Render(w http.ResponseWriter, req *http.Request, name string, vars ...any) error

Render renders an HTML template with the given name and variables.

Types

type Engine

type Engine interface {
	// ParseFS loads templates from the given fs.
	ParseFS(f fs.FS) error

	// Execute evaluates template with given name and the data context.
	Execute(w io.Writer, name string, data any) error
}

Engine is an adapter for a templating engine that is used by a Renderer.

func NewEngine

func NewEngine(config *EngineConfig) Engine

NewEngine creates a a new Engine backed by template/html.

type EngineConfig

type EngineConfig struct {
	Root      string
	Extension string
	Funcs     template.FuncMap
}

type Renderer

type Renderer interface {
	// Render renders a template with the given name and data.
	Render(w io.Writer, name string, data any) error
}

Renderer renders a template using provided underlying engine.

func New

func New(f fs.FS, e Engine) (Renderer, error)

Jump to

Keyboard shortcuts

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