Timill Platform Documentation

Gonja Reference

Complete reference for the Gonja (Jinja2-compatible) template surface: globals, methods, filters and functions.

Scripted widgets render with Gonja, a Jinja2-compatible template engine. This page is the complete reference for what a Gonja template can read and call. For what to build with it, see Scripted Widgets; for the equivalent JavaScript surface used by backend scripts and scripted charts, see the API Reference and Differences from the JavaScript API below.

Data is exposed as plain values ({{ user.name }}, no parens) and actions as functions on the same object ({{ group.queryItems("…") }}, with parens) — the same shape as the JavaScript API, so the two are easy to read side by side.

Metadata globals#

VariableTypeDescription
userIdstringCurrent user’s ID
groupIdstringCurrent group’s ID (empty if not group-scoped)
instanceIdstringInstance ID
scriptIdstringThe widget’s script ID
scriptTypestringAlways "widget" for scripted widgets
itemIdstringCurrent item’s ID — only set when the widget is placed on an item’s page

user#

The current user. Always available.

KeyTypeDescription
user.idstringUser ID
user.namestringDisplay name
user.emailstringEmail address
user.profilePicturestringAvatar URL (empty if none)
user.localestringLanguage preference
user.isActivebooleanWhether the account is active
Welcome, {{ user.name }}!

There is no user.firstName / user.lastName.

group#

The current group. Present when the widget is scoped to a group.

KeyTypeDescription
group.idstringGroup ID
group.namestringGroup name
group.queryItems(query)(string) -> item[]Run a query, RBAC-filtered. See Query Language.
group.getMembers()() -> user[]All members of the group, as user objects
group.getMemberById(id)(string) -> user | nullOne member by user ID
group.getItemTypes()() -> {id, name, description, icon}[]The group’s item types
group.getStatuses(typeId)(string) -> {id, name, color, icon, enabled}[]Statuses of one item type
group.getFields(typeId)(string) -> {id, name, description, type, icon}[]All fields (default + custom) of one item type
group.getDefaultFields(typeId)(string) -> {id, name, description, type, icon}[]Only the built-in fields
group.getCustomFields(typeId)(string) -> {id, name, description, type}[]Only the custom fields

There is no group.description, group.icon or group.color.

{% set open = group.queryItems("completedDate:$empty") %}
<h3>{{ group.name }} — {{ open|length }} open</h3>

{% set assignee = group.getMemberById(item.assignedTo) %}
{% if assignee %}Assigned to {{ assignee.name }}{% endif %}

A queryItems call with a query string the parser rejects aborts the whole render with the parser’s error; it does not return an empty list.

item#

One item — either the page’s current item (when the widget is item-scoped) or an entry from group.queryItems(...). Same shape in both cases.

Data#

KeyTypeDescription
item.idstringItem ID
item.titlestringTitle
item.descriptionstringDescription (plain text/HTML per the item type)
item.statusstringStatus ID (empty if unset)
item.typestringItem type ID
item.groupIdstringOwning group ID
item.idInGroupnumberThe #N shown in the tag
item.tagstringThe #N tag string
item.createdBystringAuthor’s user ID
item.assignedTostringAssignee’s user ID (empty if unset)
item.isCompletedbooleanWhether the item has reached a completing status
item.createdAttime value or nullCreation time
item.updatedAttime value or nullLast update time
item.dueDatetime value or nullDue date
item.completedAttime value or nullCompletion time

createdAt / updatedAt / dueDate / completedAt are time values, not strings — format them with date() / datetime(). An unset one is null and formats to "" with no guard needed.

Actions#

MethodReturnsDescription
item.getField(fieldId)plain valueAny field (built-in or custom) as a plain value. See Field values.
item.readAttachment(attachmentId)attachment + text()/base64()Read one of the item’s own files, up to 10MB. See Files and attachments.
item.renderField(fieldId)safe HTMLThe field rendered the way the platform UI renders it (status chip, user avatar, formatted date, …)
item.render(kwargs)safe HTMLThe item as the platform’s standard link

item.getField returns dates as ISO strings (unlike the item.dueDate-style properties above, which are time values) — date()/datetime() accept either.

item.render() draws the standard item link: type icon, #tag pill, title, an open-in-new-window arrow, and a click that opens the side panel. All four parts default to shown; turn any off with a boolean keyword argument:

{{ item.render() }}
{{ item.render(icon=false, tag=false) }}
{{ item.render(sidePanel=false, openInNewWindow=false) }}

Only icon, tag, sidePanel and openInNewWindow are accepted, only as keyword arguments — a positional argument or an unknown keyword is an error that aborts the render, not a silent no-op.

renderField and render return HTML the autoescaping renderer emits verbatim; |safe is unneeded on their result (harmless if present).

pageVars#

Resolved page variables, when the widget is placed on a page with variables defined. Reading pageVars.<key> is detected automatically and makes the widget re-render when that variable changes.

AccessReturns
pageVars.<key>The variable’s plain value (shape depends on its type — item variables resolve to item objects; date variables to their raw value)
pageVars.render(key)safe HTML — the value rendered the way the platform displays it (chips, formatted dates)
pageVars.display(key)string — the plain human-readable label

An unset or undefined page variable reads as falsy ({% if pageVars.foo %} works safely) rather than raising.

{% if pageVars.assignee %}
  {% set items = group.queryItems("assignee:" ~ pageVars.assignee) %}
{% endif %}
<p>Filtered by {{ pageVars.display("assignee") }}</p>

api#

Data-shaping helpers that mirror the JavaScript api object.

FunctionSignatureDescription
api.groupBy(items, field)(list, string) -> {key: item[]}Groups items by the string form of item[field]. Only a field that is entirely absent from the item, or explicitly null, is left out.
api.aggregate(items, field, fn)(list, string, string) -> numberReduces the numeric values of item[field]. fn is "sum", "avg" (or "average"), "min", "max", or "count".

Both read a top-level key of each item (status, type, assignedTo, idInGroup, …); a custom field needs item.getField(...) first.

{% set items = group.queryItems("type:task") %}
{% set byStatus = api.groupBy(items, "status") %}
{{ api.aggregate(items, "idInGroup", "max") }}

Note

An unset item property is usually "" (empty string), not missing — item.assignedTo, item.status and similar always exist on the item, they are just empty when unset. api.groupBy treats "" as a real key, so ungrouped items land in a group keyed by the empty string rather than being dropped — exactly as in JavaScript. Test for the "" key in the loop if you want to label that group instead of showing a blank heading.

Both helpers accept queryItems() results and lists you write in the template ({% set xs = [{"status": "open"}, …] %}).

There is no api.filterItems in Gonja — see Differences from the JavaScript API.

Filters and functions#

Two different things share the | and () syntax in a template, and mixing them up is the most common template error:

  • Functions are called directly: date(value), datetime(value), truncate(text, n), upper(s), lower(s), title(s).
  • Filters are called with the pipe syntax and parentheses: {{ value|truncate(n) }}, {{ value|default("n/a") }}, {{ list|length }}, plus every Jinja2 builtin filter (selectattr, rejectattr, join, round, first, last, list, …).

date and datetime are platform functions, not filters — call them as date(value, "layout"), never value|date:"layout".

Warning

The Django-style colon syntax ({{ x|date:"2006" }}, {{ x|truncate:50 }}, {{ x|default:"n/a" }}) is not supported and is a parse error that aborts the whole render: '}}' expected here ... near ":". Always use call syntax: date(x, "2006"), x|truncate(50), x|default("n/a").

Note

default only substitutes when the value is undefined, not when it is an empty string. Most item properties that can be “unset” (item.status, item.assignedTo, item.getField(...) on an empty text field, …) are "" rather than undefined, so {{ item.status|default("No status") }} will still print nothing. Pass a third argument of true to also treat falsy values ("", 0, false, empty list) as unset: {{ item.status|default("No status", true) }}.

Platform functions#

FunctionSignatureDescription
date(value, layout?)(time | string | null, string?) -> stringFormats a date. Default layout "2006-01-02". Accepts a time value, an ISO string, or null/unset (renders "").
datetime(value, layout?)(time | string | null, string?) -> stringFormats a date and time. Default layout "2006-01-02 15:04:05". Same accepted inputs as date.
truncate(text, n)(string, number) -> stringTruncates to n runes, appending "..." when truncated.
upper(s)(string) -> stringUppercase.
lower(s)(string) -> stringLowercase.
title(s)(string) -> stringTitle case.

date / datetime layouts are Go time layouts ("2006-01-02", "Jan 2, 2006", "2006-01-02 15:04", …) — the reference date Mon Jan 2 15:04:05 2006 spells out the format, there are no strftime codes.

{{ date(item.dueDate) }}                    {# 2024-12-28 #}
{{ date(item.dueDate, "January 2, 2006") }} {# December 28, 2024 #}
{{ datetime(item.updatedAt, "2006-01-02 15:04") }}
{{ item.title|truncate(50) }}
{{ item.status|default("No status", true) }}

Jinja builtin filters#

Standard Jinja2 filters work as usual, including the ones most useful for shaping a queryItems() result without api.filterItems:

{% set open = items|selectattr("status", "equalto", "open")|list %}
{% set count = items|rejectattr("assignedTo", "equalto", "")|list|length %}
{{ items|length }}
{{ (score * 100 / total)|round }}

Differences from the JavaScript API#

Gonja only renders scripted widgets, which are read-only. Everything not listed below has the same name and shape as the JavaScript API.

JavaScriptGonja
Writes (item.setField, group.createItem, …)Yes, in backend scriptsNo — Gonja templates cannot write anything
fetch(...)Yes, in backend scripts (rate-limited)No — does not exist
SecretsYes, in backend scriptsNo — does not exist
Timestamps (item.createdAt, item.dueDate, …)ISO stringsTime values — format with date()/datetime(), not string operations
api.filterItems(items, fn)Yes, takes a callbackNo — templates cannot write callbacks; use selectattr/rejectattr or {% if %}
api.groupBy / api.aggregateSame semanticsSame semantics
Filters (|truncate, |default, …)N/A (JS has no filter syntax)Jinja2 filters, call syntax only — no colon syntax

Everything else — user, group (including queryItems, getMembers, getMemberById, getItemTypes, getStatuses, getFields), item (including getField, readAttachment, renderField, render), pageVars, and the metadata globals — share the same names and shapes across both engines.

Next steps#