cardinal

Templates and sheets

cardinal_template renders Jinja templates, cardinal_sandbox runs them safely, and cardinal_sheet reads and writes CSV and XLSX.

cardinal_template

Print formats, mail templates, Notification messages and website pages are Jinja templates rendered by MiniJinja 3.

<h1>{{ doc.name }}</h1>
<p>{{ _("Total") }}: {{ doc.get_formatted("grand_total") }}</p>
{% for row in doc.items %}{{ row.item_code }} × {{ row.qty }}<br>{% endfor %}
{{ qr_svg(doc.name, 120) }}
RuleBehaviour
EscapingHTML is escaped, except in templates named .txt or .txt.j2
UndefinedPrints empty
Limits64 KB of source, plus fuel, recursion and output limits
FunctionsMiniJinja's built-ins, Python string and dict methods, _, abs_url, now, today, markdown, qr_svg, code128_svg, and the Record lookups. No others
Lookupsget_doc, get_list, get_all, get_value, get_single_value, exists, count. The 101st distinct lookup fails
&&, ||, !A syntax error that names and, or or not

Templates cannot query the database. A render that calls a lookup it has no answer for records the miss. Elixir fetches the answers and renders again. get_list runs as the user, the other lookups as the platform.

The crate also builds the print context (a read-only doc whose get_formatted formats in the site's formats), Frappe's Standard print layout, and the website's redirect and route-rule matching (/orders/<name>, /docs/<path:page>).

cardinal_sandbox

A separate binary that runs one template check or render pass per process.

TemplateService takes a slot. A node has CARDINAL_SANDBOX_LIMIT slots (16). A pass waits up to 2 seconds for one, then fails as busy.

It starts the sandbox with one length-prefixed JSON request on stdin.

The sandbox renders under a 64 MB heap, 2 seconds of CPU and no core file, and writes the answer to stdout.

A pass that exceeds its limits ends with kind memory, time or crash. One still alive after 10 seconds is killed.

A template that loops forever or eats memory ends its own process. The node keeps serving.

cardinal_sheet

Data Import and export read and write spreadsheets here.

DirectionDoes
ReadCSV and XLSX into cells, header matching, child rows grouped under their parent, values parsed in the user's locale into wire forms
WriteCSV and XLSX with amounts kept exact and formula-like text escaped, so a cell starting with = cannot run in a spreadsheet

The crate is server only. It has no WASM build.

On this page