DocsOverview

Overview

An overview of the functionality and the modifier functions.

A zero-dependency templating engine for Go, built for workflows, document generation, and data transformations.

{{ response | from_json | key:'orders' | filter:'status','paid' | pluck:'total' | sum | decimal:2 }}

That one line takes a raw JSON response, drills into the orders, keeps the paid ones, pulls out every total, adds them up, and formats the result to two decimals. No Go code, no helper functions, no glue.

Getting started

go get github.com/toaweme/sintax
import (
	"github.com/toaweme/sintax"
	"github.com/toaweme/sintax/defaults"
)

out, err := sintax.Render(
	"{{ users | filter:'active',true | pluck:'email' }}",
	vars,
	defaults.All(),
)

Here out is the value the template produced, not text. Render hands back any, so a pipeline that ends in a slice of emails gives you that slice with its type intact. When text is what you want, call RenderString instead and sintax formats the result for you.

The full source lives on GitHub. For the Go API in depth, see the Quick Guide.

The problem

Go's text/template was built to render HTML and text. The moment you need to actually transform data, filter a slice, sum a column, parse embedded JSON, you leave the template and write Go. Sintax moves the transformation into the template, where you can read it top to bottom.

Why sintax

  • Familiar syntax. Jinja2-style pipes that read left to right. If you have written a Django or Ansible template, you already know it.
  • 57 built-in modifiers. String operations, collection operations, conversion, formatting, file paths, and defaults, all shipping in the box. text/template ships around 14.
  • Returns values, not just text. Render returns any. A template that resolves to a slice gives you a slice, with its type intact, not a stringified version of one. Reach for RenderString when the output is a document and you want text.
  • Typed errors. Parse failures, missing variables, and circular references surface as distinct sentinel errors you can branch on with errors.Is.
  • Dependency resolution. Variables can reference each other, and sintax resolves them in the correct order. Circular references are caught at resolution time, not at runtime.
  • Zero dependencies. The core imports only the standard library. Nothing to audit, nothing to keep offline, nothing that ships a transitive tree behind your back.
  • Extensible. Register your own modifiers as a single function type, or override a built-in by name.

What it looks like

Chain modifiers to transform any value in one expression.

{{ text | trim | upper }}
{{ items | join:',' }}
{{ value | default:'n/a' }}

Loop over slices and maps with auto-bound index, first, last, and key helpers.

{{ for i, u in users }}{{ i }}: {{ u | key:'email' | lower }}
{{ endfor }}

Branch with conditionals.

{{ if active }}yes{{ else }}no{{ endif }}

The Template Syntax page covers all of these in full, along with whitespace control.

Include and render another template, with a recursion guard and a directory whitelist for safety.

{{ 'partial.tpl' | file | template }}

Where it fits

Reach for sintax when you are generating documents, shaping data for an API call, or wiring template-driven steps into a workflow, and you want the transformation to live in the template instead of scattered across Go helpers.

Reach for html/template instead when you are rendering HTML from untrusted input. Sintax ships manual escape modifiers (escape_html, escape_js, escape_url), but it does not auto-escape by context the way the standard library does, and that automatic, context-aware escaping is what keeps untrusted input safe.

Modifiers

Each modifier function links to its own page with full inputs, parameters, and examples.

Casing

Shift case: upper, lower, title, and slug.

Edit

Replace, wrap, shorten, and reshape strings.

Split & join

Split strings into parts and join them back together.

Trim

Strip whitespace, prefixes, and suffixes.

Escape

Escape strings for HTML, URLs, and JavaScript.

Format

Format numbers and strings for display.

Access

Reach into arrays and maps by key or position.

Query

Filter, test, and search collections.

Transform

Sort, map, merge, and fold collections.

File

Read a file's contents into a template.

Path

Pull apart file paths - directory, name, and extension.

Parse

Read JSON, YAML, and other formats into values.

Serialize

Render values as JSON, YAML, and Markdown.

Compare

Compare values for use in conditional expressions.

Default

Supply a fallback when a value is missing.

Template

Render a nested template.