template

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package template provides template rendering functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(cfg *Config)

Configure initializes the template system with the provided configuration. It sets up the filesystem, template extensions, i18n function name, and layouts, then caches all templates found in the filesystem. Panics if any required configuration value is missing or invalid.

func GetPartialFuncWithI18n

func GetPartialFuncWithI18n(
	templatePath string,
	i18nFunc func(string, ...any) string,
) func(name string, data any) (htmlTemplate.HTML, error)

GetPartialFuncWithI18n creates a partial template function with i18n support. If i18nFunc is nil, uses the default funcMap i18n function. This allows partials to use per-request i18n printers for proper translation.

func GetTextPartialFuncWithI18n

func GetTextPartialFuncWithI18n(
	templatePath string,
	i18nFunc func(string, ...any) string,
) func(name string, data any) (string, error)

GetTextPartialFuncWithI18n creates a text partial template function with i18n support. If i18nFunc is nil, uses the default funcMap i18n function. This allows text partials to use per-request i18n printers for proper translation.

func LookupTemplate

func LookupTemplate(path string, absolute bool) (*htmlTemplate.Template, bool)

LookupTemplate retrieves a cached template by path. If absolute is true, uses the path as-is. If false, prepends the configured base path. Returns the template and true if found, or nil and false if not found.

func Must

func Must[T any](v T, err error) T

Must is a helper that panics if err is not nil, otherwise returns v. Useful for wrapping function calls during initialization.

Types

type Config

type Config struct {
	FS                    fs.FS
	LayoutBaseName        string
	HTMLTemplateExtension string
	TextTemplateExtension string
	I18nFuncName          string
}

Config holds the configuration for template rendering.

func Configuration

func Configuration() (Config, bool)

Configuration returns the current template configuration. Returns the config and true if templates are configured, or an empty config and false if not configured.

Jump to

Keyboard shortcuts

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