Timill Platform Documentation

Scripted Widgets

Build a dashboard widget from a Gonja (Jinja2-compatible) template with read-only, RBAC-checked access to the group's data.

A scripted widget renders a Gonja (Jinja2-compatible) template to HTML on the server, on every load of the page that hosts it. It is read-only: a widget can query and display the group’s items, but cannot create, update or delete anything, call an external API, or read secrets. For automation or writes, use a backend script instead.

Creating a widget#

  1. Add a Scripted Widget to a page or dashboard.
  2. Give it a title and pick the group it queries (a specific group, or $current to follow the page).
  3. Write the Gonja template in the Gonja Template Code field.
  4. Save. The widget re-renders on every page load, and again whenever a watched page variable changes (see Reacting to page variables below).

Scripted widgets are a Plus-tier feature; on a Free group that already has one saved (e.g. after a plan downgrade), the widget shows an upgrade notice instead of running the template.

The template model#

The template’s only job is to produce the HTML that goes inside the widget’s tile. There is no separate “params” block and no wrapping document — write the markup directly:

<div class="space-y-2">
  <h3 class="text-lg font-semibold">{{ group.name }}</h3>
  {% set items = group.queryItems("completedDate:$empty") %}
  <p>{{ items|length }} open item(s)</p>
</div>

Everything the template can read is described in full on the Gonja Reference page: the user, group, item (when the widget is placed on an item’s page) and pageVars globals, the api.groupBy / api.aggregate helpers, and the date / datetime / truncate / upper / lower / title functions. This page focuses on the widget-specific parts: how the template is invoked, escaped, sanitized and limited.

Examples#

Item list with an empty state#

<div class="bg-white dark:bg-gray-800 rounded-lg">
  {% set items = group.queryItems("completedDate:$empty") %}
  {% if items %}
    <ul class="divide-y divide-gray-200 dark:divide-gray-700">
      {% for it in items %}
        <li class="py-2 flex items-center justify-between">
          {{ it.render() }}
          {{ it.renderField("status") }}
        </li>
      {% endfor %}
    </ul>
  {% else %}
    <p class="text-gray-500 p-4">No open items.</p>
  {% endif %}
</div>

it.render() draws the item exactly like the rest of the app does — type icon, #tag, title, side-panel click — instead of hand-built markup that would drift from the real component. it.renderField("status") draws the same status chip the item table uses.

Counts by status with api.groupBy#

api.groupBy and api.aggregate read a top-level key of each item (status, type, assignedTo, idInGroup, …), so they work on the items group.queryItems() returns, and on lists you write in the template with {% set %}. An unset property is usually "", not missing, so unset items land in a group keyed by the empty string rather than being dropped — see the note in the Gonja Reference.

{% set items = group.queryItems("type:task") %}
{% set byStatus = api.groupBy(items, "status") %}
<div class="grid grid-cols-3 gap-4">
  {% for status, group_items in byStatus.items() %}
    <div class="bg-gray-50 dark:bg-gray-900 p-3 rounded text-center">
      <div class="text-2xl font-bold">{{ group_items|length }}</div>
      <div class="text-sm text-gray-500">{{ status }}</div>
    </div>
  {% endfor %}
</div>

Filtering without api.filterItems#

There is no api.filterItems in Gonja (it takes a callback in JavaScript, which a template cannot write). Use Jinja’s selectattr / rejectattr, or an {% if %} inside the loop:

{% set mine = group.queryItems("")|selectattr("assignedTo", "equalto", userId)|list %}
<p>You have {{ mine|length }} item(s) assigned.</p>

Dates, without a null guard#

date() and datetime() accept an unset value (null / None) and print an empty string, so no {% if %} guard is needed just to format a date that might not be set:

{% for it in group.queryItems("type:task") %}
  <div>{{ it.title }} — due {{ date(it.dueDate, "Jan 2, 2006") }}</div>
{% endfor %}

Reacting to page variables#

A direct read like {{ pageVars.status }} is detected automatically and already causes the widget to re-render when that page variable changes. The Re-render when these page settings change parameter is only needed for a dynamic key lookup the auto-detection cannot see, e.g. pageVars[someKey].

{% if pageVars.assignee %}
  {% set items = group.queryItems("assignee:" ~ pageVars.assignee) %}
{% else %}
  {% set items = group.queryItems("") %}
{% endif %}
<p>{{ items|length }} item(s){% if pageVars.assignee %} for {{ pageVars.display("assignee") }}{% endif %}</p>

Autoescaping and output handling#

Scripted widgets compile with Jinja2 autoescaping on. Every {{ … }} interpolation of a plain value is HTML-escaped:

{{ item.title }}            {# escaped — safe even if the title contains markup #}
{{ item.getField("notes") }} {# escaped #}

This matters because item field values can be set by a lower-privileged group member and are then rendered into a dashboard every member sees — without escaping, a title of <img src=x onerror=…> would execute for every viewer. Do not add |safe to plain data to “fix” a display issue; that reopens the hole.

The helpers that return the platform’s own HTML are the exception: item.render(), item.renderField(fieldId) and pageVars.render(key) return already-safe HTML and are emitted as is. |safe on their result is harmless but unnecessary.

Static HTML you type directly in the template (<div>, <table>, your own <style> block) is never escaped — autoescaping applies only to interpolated {{ … }} values, not to the literal template text.

What the platform strips from your output#

Because static template text is emitted as written, the platform still runs every widget’s rendered HTML through a sanitizer before it reaches the page, so a template cannot turn a shared dashboard into a stored-XSS or navigate-on-load vector:

  • <script> elements (inline or with src) are removed entirely.
  • Inline event-handler attributes (onclick, onload, onerror, …) are removed.
  • javascript: URLs in href/src/action/formaction/data/poster are removed.
  • srcdoc, and data:/blob: documents in <iframe>/<frame>/<object>/<embed>, are removed.
  • <meta http-equiv="refresh"> and <base> are removed.

Alpine.js and htmx attributes are kept, under one rule: nothing in your markup may navigate the viewer without their own click, key press or form submit. A user-initiated event handler (@click, @submit, @keydown, …) can do anything, including navigate. A load-time expression or a non-user event (x-data, x-init, x-show, @mouseenter, hx-trigger’s load / revealed / every …, hx-boost, out-of-band swaps, …) is kept as long as it cannot reach location, history, window, document, .href, .submit(), eval, and similar escape hatches — otherwise it is dropped. x-html is always removed (it would inject unescaped HTML past this sanitizer). This is why widgets cannot redirect the page or hijack it into another tab on load, even from a <script>-free markup trick.

Use Alpine for interactivity instead of inline handlers:

<div x-data="{ open: false }">
  <button @click="open = !open">Details</button>
  <p x-show="open">{{ item.description }}</p>
</div>

Limits#

Scripted widgets run under the platform’s strict resource limits: a 10-second timeout, and a memory ceiling of 25 MB. See Limits and errors for what happens when a render hits one of these. A widget also cannot make network requests (fetch does not exist in Gonja) — that rules out one class of runaway external call entirely.

Errors#

If the template fails to parse or fails during execution — a syntax error, a query the parser rejects, readAttachment on a file that is not on the item, or a limit exceeded — the widget’s tile shows an inline error box instead of your markup:

Template Error

(the error message)

There is no partial render: either the whole template produces HTML, or the tile shows the error box. Common causes:

  • Django-style colon filter syntax ({{ x|date:"2006" }}) is not supported and is a parse error. Use call syntax: {{ date(x, "2006") }} (a function) or {{ x|truncate(50) }} / {{ x|default("n/a") }} (filters).
  • A bad group.queryItems(...) query string aborts the render with the parser’s error message.
  • Referencing a field or method that does not exist on an object (a typo) raises rather than rendering blank.

See Limits and errors for the full error model shared across scripting surfaces.

Next steps#