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#
| Variable | Type | Description |
|---|---|---|
userId | string | Current user’s ID |
groupId | string | Current group’s ID (empty if not group-scoped) |
instanceId | string | Instance ID |
scriptId | string | The widget’s script ID |
scriptType | string | Always "widget" for scripted widgets |
itemId | string | Current item’s ID — only set when the widget is placed on an item’s page |
user#
The current user. Always available.
| Key | Type | Description |
|---|---|---|
user.id | string | User ID |
user.name | string | Display name |
user.email | string | Email address |
user.profilePicture | string | Avatar URL (empty if none) |
user.locale | string | Language preference |
user.isActive | boolean | Whether 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.
| Key | Type | Description |
|---|---|---|
group.id | string | Group ID |
group.name | string | Group 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 | null | One 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#
| Key | Type | Description |
|---|---|---|
item.id | string | Item ID |
item.title | string | Title |
item.description | string | Description (plain text/HTML per the item type) |
item.status | string | Status ID (empty if unset) |
item.type | string | Item type ID |
item.groupId | string | Owning group ID |
item.idInGroup | number | The #N shown in the tag |
item.tag | string | The #N tag string |
item.createdBy | string | Author’s user ID |
item.assignedTo | string | Assignee’s user ID (empty if unset) |
item.isCompleted | boolean | Whether the item has reached a completing status |
item.createdAt | time value or null | Creation time |
item.updatedAt | time value or null | Last update time |
item.dueDate | time value or null | Due date |
item.completedAt | time value or null | Completion 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#
| Method | Returns | Description |
|---|---|---|
item.getField(fieldId) | plain value | Any 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 HTML | The field rendered the way the platform UI renders it (status chip, user avatar, formatted date, …) |
item.render(kwargs) | safe HTML | The 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.
| Access | Returns |
|---|---|
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.
| Function | Signature | Description |
|---|---|---|
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) -> number | Reduces 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#
| Function | Signature | Description |
|---|---|---|
date(value, layout?) | (time | string | null, string?) -> string | Formats 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?) -> string | Formats a date and time. Default layout "2006-01-02 15:04:05". Same accepted inputs as date. |
truncate(text, n) | (string, number) -> string | Truncates to n runes, appending "..." when truncated. |
upper(s) | (string) -> string | Uppercase. |
lower(s) | (string) -> string | Lowercase. |
title(s) | (string) -> string | Title 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.
| JavaScript | Gonja | |
|---|---|---|
Writes (item.setField, group.createItem, …) | Yes, in backend scripts | No — Gonja templates cannot write anything |
fetch(...) | Yes, in backend scripts (rate-limited) | No — does not exist |
| Secrets | Yes, in backend scripts | No — does not exist |
Timestamps (item.createdAt, item.dueDate, …) | ISO strings | Time values — format with date()/datetime(), not string operations |
api.filterItems(items, fn) | Yes, takes a callback | No — templates cannot write callbacks; use selectattr/rejectattr or {% if %} |
api.groupBy / api.aggregate | Same semantics | Same 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#
- Scripted Widgets — how to build and ship a widget.
- Field values — the full
getFieldtable by field type. - Files and attachments —
readAttachmentin depth. - Query Language — the
queryItemsquery syntax. - Limits and errors — timeouts, memory, and how errors surface.