Documentation
¶
Overview ¶
Package template provides template rendering and variable substitution.
This package implements a flexible template system that can be used by both prompts and personas. It supports:
- Variable substitution with {{variable}} syntax
- Recursive template resolution (variables can contain other variables)
- Validation of required variables
- Detection of unresolved placeholders
Future versions may support more advanced templating engines like Go templates (similar to Helm charts) for conditional logic, loops, and functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetUsedVars ¶
GetUsedVars returns a list of variable names that had non-empty values. This is useful for debugging and logging which variables were actually used.
Types ¶
type Renderer ¶
type Renderer struct {
}
Renderer handles variable substitution in templates
func (*Renderer) MergeVars ¶
MergeVars merges multiple variable maps with later maps taking precedence. This is useful for combining default values, context variables, and overrides.
Example:
defaults := map[string]string{"color": "blue", "size": "medium"}
overrides := map[string]string{"color": "red"}
result := MergeVars(defaults, overrides)
// result = {"color": "red", "size": "medium"}
func (*Renderer) Render ¶
Render applies variable substitution to the template with recursive resolution.
The renderer performs multiple passes (up to maxPasses) to handle nested variable substitution. For example, if var1="{{var2}}" and var2="value", the final result will correctly resolve to "value".
Returns an error if any placeholders remain unresolved after all passes.