Documentation
¶
Overview ¶
Package template provides template rendering functionality.
Index ¶
- func Configure(cfg *Config)
- func GetPartialFuncWithI18n(templatePath string, i18nFunc func(string, ...any) string) func(name string, data any) (htmlTemplate.HTML, error)
- func GetTextPartialFuncWithI18n(templatePath string, i18nFunc func(string, ...any) string) func(name string, data any) (string, error)
- func LookupTemplate(path string, absolute bool) (*htmlTemplate.Template, bool)
- func Must[T any](v T, err error) T
- type Config
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.
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 ¶
Configuration returns the current template configuration. Returns the config and true if templates are configured, or an empty config and false if not configured.