Miya Engine¶
A high-performance Jinja2-compatible template engine for Go.
Features¶
- Jinja2 Compatibility: Parse and render Jinja2 templates with familiar syntax
- High Performance: Optimized for speed with template compilation, caching, and AST node pooling
- Memory Efficient: Optional
Release()method for returning pooled nodes to reduce GC pressure - Template Inheritance: Full support for extends, blocks, and includes
- Rich Filter System: Built-in filters plus support for custom filters
- Flexible Loading: Load templates from filesystem, memory, or embedded resources
- Security: Auto-escaping enabled by default to prevent XSS
- Thread Safe: Safe for concurrent use in web applications
- Developer Friendly: Clear error messages with line numbers and debugging support
Installation¶
Quick Start¶
package main
import (
"fmt"
"log"
"github.com/zipreport/miya"
)
func main() {
env := miya.NewEnvironment()
tmpl, err := env.FromString("Hello {{ name }}!")
if err != nil {
log.Fatal(err)
}
ctx := miya.NewContext()
ctx.Set("name", "World")
output, err := tmpl.Render(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println(output) // Output: Hello World!
}
Supported Syntax¶
| Syntax | Description |
|---|---|
{{ variable }} |
Variable substitution |
{% if %}...{% endif %} |
Conditional statements |
{% for %}...{% endfor %} |
Loop iteration |
{% extends %} |
Template inheritance |
{% block %}...{% endblock %} |
Override blocks |
{% include %} |
Include templates |
{% macro %}...{% endmacro %} |
Reusable macros |
{{ value\|filter }} |
Filter application |
{# comment #} |
Comments |
{%- -%} / {{- -}} |
Whitespace control |
Documentation¶
Getting Started¶
- Usage Guide - Loading templates, contexts, concurrency, web server integration
Core Features¶
- Template Inheritance - Learn about extends, blocks, and super() for template composition
- Control Structures - If/elif/else, for loops, set, and with statements
- Filters - 70+ built-in filters for data transformation
- Tests & Operators - 26+ test functions and all operators
Advanced Features¶
- Advanced Guide - Filter blocks, whitespace control, autoescape
- Macros & Includes - Reusable components and template composition
- Global Functions - range, dict, cycler, joiner, namespace
- Comprehensions - List and dict comprehensions
Reference¶
- Comprehensive Features - Complete feature overview
- Jinja2 Compatibility - Feature comparison matrix
- Limitations - Known limitations and workarounds
Why Miya?¶
| Feature | Miya | Other Go Template Engines |
|---|---|---|
| Jinja2 Syntax | Full compatibility | Partial or none |
| Template Inheritance | Full support | Limited |
| Filters | 70+ built-in | Varies |
| List Comprehensions | Supported | Rare |
| Thread Safety | Yes | Varies |
| Performance | Optimized with pooling | Varies |
License¶
MIT License - see LICENSE for details.