template

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package template provides templates for rendering HTML pages.

Index

Constants

This section is empty.

Variables

View Source
var ErrFailedToParse = errors.New("failed to parse templates")

ErrFailedToParse is an error that is returned when the templates fail to parse.

Functions

func RenderTemplateHTML

func RenderTemplateHTML[T any](template Templater[T], w http.ResponseWriter, data T) error

RenderTemplateHTML sets the Content-Type header to text/html and executes the given template.

Types

type Engine

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

Engine is a Templater that uses embedded templates.

func New

func New(fs fs.FS) *Engine

New creates a new template Engine.

func NewEmbedded

func NewEmbedded() *Engine

NewEmbedded creates a new template engine using the embedded templates.

func (*Engine) HomePage

func (tfs *Engine) HomePage() PageTemplate[HomePageData]

HomePage returns a handle to the template for the home page.

type HomePageData

type HomePageData struct{}

HomePageData is the data needed to render the home page.

type PageTemplate

type PageTemplate[T any] struct {
	// contains filtered or unexported fields
}

PageTemplate is a template for a specific page.

func (PageTemplate[T]) ExecuteTemplate

func (p PageTemplate[T]) ExecuteTemplate(wr io.Writer, data T) error

ExecuteTemplate executes a template with the given data.

type Templater

type Templater[T any] interface {
	ExecuteTemplate(wr io.Writer, data T) error
}

Templater is an interface for rendering templates.

Jump to

Keyboard shortcuts

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