Skip to content
Jennifer Programming Language

tengine API reference

A small text template engine for lightweight CMS-style rendering - a subset of Go's text/template (the Go / Hugo style), evaluated directly over a json.Value data tree. There is no compile step and no AST: the engine re-scans block bodies as it renders, which is fine at page / CMS scale. Dotted paths resolve as JSON Pointers against the current node (.a.b -> /a/b; . is the current node); $ is the root node, $var a variable; a missing key renders as empty.

SECURITY: output is not auto-escaped (this is text/template, not html/template). Rendering untrusted data into an HTML page is an XSS hole unless you escape it yourself: pipe every value that reaches HTML through the html pipe ({{ .userInput | html }}), or escape upstream. The engine will emit whatever the data contains, <script> included.

Actions: value output; if / else if / else with the comparison / boolean functions eq ne lt le gt ge and or not (parenthesised nesting allowed); range (with an optional $i, $e := index / element bind) and with, each with an else; variable assignment {{ $x := PIPE }}; {{ define }} / {{ template }} / {{ block }} layout inheritance; {{/* comments */}}; {{- / -}} whitespace-trim markers; and output pipes upper lower title trim html urlize default truncate join len. Over the compiled-in json / strings / lists / maps / convert libraries, so it runs on both binaries.

Import with import "tengine.j" as tengine;. See the tengine guide for prose and examples.

Contents

NameWhat it is
addAdd a template source under name, returning a new Set.
newSetCreate an empty template set.
renderRender the named template against a json.Value data tree.
Setstruct: A value-semantic set of named template sources (kept as two parallel lists).

Functions

add

jennifer
tengine.add(set as Set, name as string, src as string)

Add a template source under name, returning a new Set. Any top-level {{ define "x" }}...{{ end }} blocks are pulled out and registered as their own entries x, so a page can define the sections its base layout pulls in. Whitespace-trim markers ({{- / -}}) are applied as the source is stored. A name (or a defined name) already in the set is replaced.

set
the set to extend
name
the template name
src
the template source text
Returns Set
a new Set with the template (and any defines) added
Throws Error
kind "tengine" on an unterminated action

newSet

jennifer
tengine.newSet()

Create an empty template set.

Returns Set
a fresh, empty set

render

jennifer
tengine.render(set as Set, entry as string, data as json.Value)

Render the named template against a json.Value data tree.

set
the template set
entry
the name of the template to render
data
the root data node
Returns string
the rendered output
Throws Error
kind "tengine" if entry (or a referenced template) is absent

Structs

Set

A value-semantic set of named template sources (kept as two parallel lists). Build it with newSet, populate it with add, and render an entry with render.

jennifer
def struct Set {
    names as list of string,
    sources as list of string
};
names
the template names
sources
the template sources, positionally paired with names