Documentation
¶
Overview ¶
Package templates provides plugins access to Go templates.
Configuration: |-----------------------------------|-----------------------| | Env | JSON | | ----------------------------------|-----------------------| | PF__TEMPLATES__ALWAYSPARSE | templates.alwaysparse | | PF__TEMPLATES__DIRS | templates.dirs | |-----------------------------------|-----------------------|
Index ¶
Constants ¶
const PluginName = "templates"
Constant name for identifying the templates plugin.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TemplateData ¶
type TemplateData struct {
// Data contains the user-provided data passed to Render.
Data interface{}
// Config contains all configuration values from prefab.Config.
Config map[string]interface{}
}
TemplateData is the wrapper struct passed to all templates during rendering. Templates should access the original data via .Data and configuration via .Config.
type TemplatePlugin ¶
type TemplatePlugin struct {
// contains filtered or unexported fields
}
TemplatePlugin exposes utilities for reading and rendering go templates.
func (*TemplatePlugin) Load ¶
func (p *TemplatePlugin) Load(dirs []string) error
Load templates (*.tmpl) contained within the provided directory and all sub-directories.
func (*TemplatePlugin) Render ¶
Render executes a template by name with the provided data.
The data parameter is wrapped in a TemplateData struct before being passed to the template. Within templates, access your data fields using .Data.FieldName, not .FieldName directly. The Config field provides access to all configuration values.
Example template usage:
Hello, {{.Data.Name}}!
App version: {{.Config.app.version}}