https://github.com/karpeleslab/tpl
Template engine for Go
https://github.com/karpeleslab/tpl
Last synced: 4 months ago
JSON representation
Template engine for Go
- Host: GitHub
- URL: https://github.com/karpeleslab/tpl
- Owner: KarpelesLab
- License: mit
- Created: 2020-01-17T17:11:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2026-01-17T15:34:53.000Z (5 months ago)
- Last Synced: 2026-01-17T15:35:56.151Z (5 months ago)
- Language: Go
- Size: 217 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://godoc.org/github.com/KarpelesLab/tpl)
[](https://github.com/KarpelesLab/tpl/actions/workflows/test.yml)
[](https://coveralls.io/github/KarpelesLab/tpl?branch=master)
# Template Engine for Go
This is a legacy template engine system, made to be compatible with an older version initially written in PHP.
## Features
- 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
## Usage
See the [SYNTAX.md](SYNTAX.md) file for template syntax documentation.
```go
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!
}
```
## License
This project is released under the MIT license.