Word templates

Template variables

Every command sees these variables.

Overview

VariableContent
$oThe current object. In templates with one document per object, the object currently being rendered; in templates with one document for all, the first one
objectsArray of all loaded objects, in the filter and sort order of the view
fField definitions, by field name: f[`Gewicht`] returns the definition including its configuration
pProject data
$fFiles of the current object
filesAll files, grouped by object ID
$mField annotations of the current object (colour, comment, source)
$eThe events of the current object
$lThe links of the current object, by link type
$fmtThe formatted field values of the current object (output formatter)
uiView 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

PropertyContent
p.project_idID
p.nameName
p.name_enEnglish name
p.start_dateStart
p.end_dateEnd
p.placePlace
p.statusStatus
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

PropertyContent
file_idID
nameStored file name
textFreely chosen text, usually used as a descriptive name
extensionExtension
kindimage · image_other · svg · pdf · audio · video · 3D · file
keywordsKeywords, comma-separated
descriptionDescription
width, heightSize in pixels
modifier1 to 3Markings, crop, text recognition

Each entry also carries the ID as id. That is why file objects from $f can go straight to img().

Files are loaded only when needed

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

JS
files = {
  "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.

PropertyContent
type, type_labelKey and label of the event type, for example ausstellung (exhibition)
titleTitle of the event
is_sharedWhether it is a shared event
actor_text, actor_label, actor_person_labelFirst actor: free text, from the authority data, from the address book
actor_gnd_id, actor_wikidata_idIDs of the first actor
actor_roleRole of the first actor
actorsAll actors, each with actor_text, actor_label, actor_person_label, actor_gnd_id, actor_wikidata_id, actor_role, actor_attribution
place_textPlace as free text
place_label, place_gnd_id, place_wikidata_idPlace from the authority data
date_from, date_toPeriod of the event
date_textDisplay dating
descriptionDescription
culture, period_name, method, materials_tech, attribution_qualifierFurther details of the event, for example for production and attribution
roleRole or catalogue number of this object in this event
date_from_override, date_to_overridePeriod for this object only
note, source, comment, color, hesitantDetails 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.

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.

PropertyContent
targetThe 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_idThe number of the target, even without read permission
extraThe additional fields of the type, for example extra.page for the page
type_key, type_labelKey and name of the type
libraryThe library: normdata, address, object or file
hesitant, sourceUncertain and source of the link
sort_orderPosition 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

KeyMeaningDefault
ui.checkbox_yes, ui.checkbox_noHow switch fields are shown✅ / ❌
ui.date_formatDate format as a pattern (DD.MM.YYYY, D. MMMM YYYY …) or false for unformattedDD.MM.YYYY
ui.float_formatNumber format: de-DE, en-US, de-CH, fr-FR, en-ISOde-DE
ui.null_replacementReplacement text for empty valuesn/a

The defaults are those of the view settings . If there is no setting at export time, Moliri uses Ja and Nein for switches.

When not to use ui

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