Word templates
Template variables
Every command sees these variables.
Overview
| Variable | Content |
|---|---|
$o | The current object. In templates with one document per object, the object currently being rendered; in templates with one document for all, the first one |
objects | Array of all loaded objects, in the filter and sort order of the view |
f | Field definitions, by field name: f[`Gewicht`] returns the definition including its configuration |
p | Project data |
$f | Files of the current object |
files | All files, grouped by object ID |
$m | Field annotations of the current object (colour, comment, source) |
$e | The events of the current object |
$l | The links of the current object, by link type |
$fmt | The formatted field values of the current object (output formatter) |
ui | View settings of the exporting user (read only) |
objects, f, files and p are the same for all objects of an export run. Even in a template with one
document per object, objects is complete: {#objects.length#} outputs the number of all exported
objects there.
$o: the current object
{#$o[`RegNr`] ?? ``#} {#$o[`Originaltitel`] ?? ``#} {#$o.object_id#}
Fields are addressed by their field name, in backticks. The fallback with ?? and an empty string is
the standard style. The value is always the raw value as stored: numbers as strings, dates as YYYY-MM-DD. imask, fdate, fcheck and ffmt give readable forms.
Subfields: both notations
Address, object and geolocation fields have subfields. Moliri provides them nested and also keeps the original key. Both forms work:
{#$o[`Leihgeber`]?.address_designation ?? ``#} nested {#$o[`Leihgeber~address_designation`] ?? ``#} literal
For nested access always use ?. rather than .: if the field is missing in the project or empty, $o[`Leihgeber`] is undefined. With . the expression fails, with ?. the fallback applies.
Switch fields
Switch fields return the stored value, usually 1 for yes. In JavaScript the string '0' counts as true. A plain truth test such as $o[`Kurierbegleitung`] ? … is therefore wrong. Either compare
explicitly or use fcheck , which also reads
custom stored values correctly:
Kurierbegleitung: {#($o[`Kurierbegleitung`] == 1) ? `Ja` : `Nein`#} Kurierbegleitung: {#fcheck($o[`Kurierbegleitung`], `Ja`, `Nein`)#}
objects: all objects
{# FOR obj IN objects #} {# INS $obj[`RegNr`] ?? `` #} {# END-FOR obj #}
As soon as a FOR loop runs over objects, one document is created for all objects. See Template syntax .
f: field definitions
Contains the definition of each field including its configuration. Mainly for imask():
{# INS imask($o[`Breite`], f[`Breite`]) #}
The output then takes the number mask from the field configuration .
p: project data
| Property | Content |
|---|---|
p.project_id | ID |
p.name | Name |
p.name_en | English name |
p.start_date | Start |
p.end_date | End |
p.place | Place |
p.status | Status |
Projekt: {# INS p.name ?? `` #} Ort: {# INS p.place ?? `` #} Zeitraum: {# INS fdate(p.start_date) #} bis {# INS fdate(p.end_date) #}
$f: files of the current object
Equivalent to files[String($o.object_id)] ?? [].
{# FOR file IN $f #} {# IF [`image`, `image_other`, `svg`].includes($file.kind) #} {# IMAGE img($file, { width: 6 }) #} {# END-IF #} {# END-FOR file #}
Properties of a file entry
| Property | Content |
|---|---|
file_id | ID |
name | Stored file name |
text | Freely chosen text, usually used as a descriptive name |
extension | Extension |
kind | image · image_other · svg · pdf · audio · video · 3D · file |
keywords | Keywords, comma-separated |
description | Description |
width, height | Size in pixels |
modifier1 to 3 | Markings, crop, text recognition |
Each entry also carries the ID as id. That is why file objects from $f can go straight to img().
Moliri fetches files at all only if the template mentions $f or files. Also, $f does not follow the loop variable of an object loop. Inside FOR obj IN objects you write files[$obj.object_id].
files: all files by object
JSfiles = { "10349": [ /* files of object 10349 */ ], "10350": [ /* files of object 10350 */ ] }
{# FOR obj IN objects #} {# INS $obj[`RegNr`] ?? `` #} {# FOR file IN files[$obj.object_id] #} {# IMAGE img($file, { width: 6 }) #} {# END-FOR file #} {# END-FOR obj #}
$m: field annotations
JS$m = { "RegNr": { color: "red", comment: "…", source: "…" } }
Colour marking, comment and source for each field. In loops over objects, each object carries its own
annotations as $obj.__m. $m is evaluated by deco() ; you can also read it directly:
{#$m[`Datierung`]?.comment ?? ``#}
$e: events of the current object
An array of the events , in the order set on the object. In a loop
over objects, each object has its events as $obj.__events.
| Property | Content |
|---|---|
type, type_label | Key and label of the event type, for example ausstellung (exhibition) |
title | Title of the event |
is_shared | Whether it is a shared event |
actor_text, actor_label, actor_person_label | First actor: free text, from the authority data, from the address book |
actor_gnd_id, actor_wikidata_id | IDs of the first actor |
actor_role | Role of the first actor |
actors | All actors, each with actor_text, actor_label, actor_person_label, actor_gnd_id, actor_wikidata_id, actor_role, actor_attribution |
place_text | Place as free text |
place_label, place_gnd_id, place_wikidata_id | Place from the authority data |
date_from, date_to | Period of the event |
date_text | Display dating |
description | Description |
culture, period_name, method, materials_tech, attribution_qualifier | Further details of the event, for example for production and attribution |
role | Role or catalogue number of this object in this event |
date_from_override, date_to_override | Period for this object only |
note, source, comment, color, hesitant | Details of the link |
{# FOR ev IN $e #} {# IF $ev.type === `ausstellung` #} {# INS $ev.title #}{# INS combine($ev.role, { pre: ` (Kat. `, post: `)` }) #} {# END-IF #} {# END-FOR ev #}
date_from and date_to are the period of the event. date_from_override and date_to_override apply
only to this object, for example a different loan period.
$l: links of the current object
The object’s links to authority data, addresses, objects and files, by
the key of the link type: $l[`documented_in`] is the list of references “documented in”, in the
order of the link area. In a loop over objects the same list is available under $obj.__links[`object`][`documented_in`], by library and type.
| Property | Content |
|---|---|
target | The target with label, its label. For authority data also uri, gnd_id and wikidata_id. Without read permission on the target, target is empty |
target_id | The number of the target, even without read permission |
extra | The additional fields of the type, for example extra.page for the page |
type_key, type_label | Key and name of the type |
library | The library: normdata, address, object or file |
hesitant, source | Uncertain and source of the link |
sort_order | Position in the link area |
{# FOR d IN $l[`documented_in`] #} {# INS $d.target?.label ?? `` #}{# INS combine($d.extra?.page, { pre: `, S. ` }) #} {# END-FOR d #}
Types you may not read are missing from $l; a requested type without links gives an empty list. The
check in the template editor knows $l: a type that does not exist in the project or cannot be read is
listed there under Missing in project, but it is not an error.
$fmt: formatted field values
For fields with an output formatter:
{#$o[`Maße`]#} raw {#$fmt[`Maße`]#} formatted, for example 118,5 × 64 × 21 cm {#$fmt[`Maße.Objekt`]#} a single entry
$fmt belongs to the current object and is wrong in loops over objects. Use ffmt($obj, `Maße`) there. Details under Output formatters in templates .
Do not confuse it with $f, which holds the files.
ui: view settings of the person exporting
| Key | Meaning | Default |
|---|---|---|
ui.checkbox_yes, ui.checkbox_no | How switch fields are shown | ✅ / ❌ |
ui.date_format | Date format as a pattern (DD.MM.YYYY, D. MMMM YYYY …) or false for unformatted | DD.MM.YYYY |
ui.float_format | Number format: de-DE, en-US, de-CH, fr-FR, en-ISO | de-DE |
ui.null_replacement | Replacement text for empty values | n/a |
The defaults are those of the view settings . If there is no
setting at export time, Moliri uses Ja and Nein for switches.
Every access to ui makes the template user-dependent: the same document looks different for two
people. For agreements, loan slips and anything that is archived, put fixed values in the command.
Further reading
- Template syntax : the commands
- Template functions : the ten helpers
- Output formatters in templates :
ffmtand$fmt - Recipes : patterns to copy