This is a legacy template engine system, made to be compatible with an older version initially written in PHP.
- Template syntax with interpolation and control structures
- Support for custom filters and functions
- Parallel template execution
- Structured error handling with location information
- Context-aware template execution
See the SYNTAX.md file for template syntax documentation.
package main
import (
"context"
"fmt"
"github.com/KarpelesLab/tpl"
)
func main() {
// Create a new template engine
engine := tpl.New()
// Add a template
engine.Raw.TemplateData["main"] = "Hello {{_name}}!"
// Set up a context with variables
ctx := context.Background()
ctx = tpl.ValuesCtx(ctx, map[string]any{
"_name": "World",
})
// Compile templates
if err := engine.Compile(ctx); err != nil {
panic(err)
}
// Execute template
result, err := engine.ParseAndReturn(ctx, "main")
if err != nil {
panic(err)
}
fmt.Println(result) // Output: Hello World!
}This project is released under the MIT license.