template

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package template loads Go html/template files and renders pages with site data.

Package template loads Go html/template files and renders articles into HTML.

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 the concrete implementation of TemplateEngine. It loads html/template files from a theme directory and renders pages with site/article data.

func NewEngine

func NewEngine() *Engine

NewEngine returns a new, empty Engine. Call Load before calling Render.

func (*Engine) Load

func (e *Engine) Load(templateDir string, funcs template.FuncMap, defaultLocale string) error

Load parses all .html files found (recursively) under templateDir. Built-in helper functions (formatDate, tagURL, categoryURL, markdownify) are registered automatically; callers may supply additional functions via funcs. defaultLocale is the site's primary locale (e.g. "en"); pass "" for non-i18n sites. tagURL and categoryURL use it to decide when to omit the locale prefix.

func (*Engine) Render

func (e *Engine) Render(w io.Writer, templateName string, data *model.Site) error

Render executes the named template, writing the rendered output to w. templateName should match the base filename (e.g. "article.html") or the name of a {{define}} block inside a loaded file.

type TemplateEngine

type TemplateEngine interface {
	// Load parses all template files rooted at templateDir (e.g. theme/templates).
	// defaultLocale is the site's primary locale (e.g. "en"); pass "" for
	// non-i18n sites. tagURL and categoryURL use it to decide when to omit the
	// locale prefix.
	Load(templateDir string, funcs template.FuncMap, defaultLocale string) error

	// Render executes the named template with the given data, writing the result
	// to w.  templateName corresponds to a file base name such as "article.html".
	Render(w io.Writer, templateName string, data *model.Site) error
}

TemplateEngine loads theme templates from disk and renders pages using the standard library html/template package.

Jump to

Keyboard shortcuts

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