Skip to content

Miya Engine

A high-performance Jinja2-compatible template engine for Go.

Go Reference Go Report Card Test License: MIT Go Version

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

go get github.com/zipreport/miya

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

Advanced Features

Reference

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.