Paged.The open publishing system
The technical handbook
Templates

Paged Docs

Templates

A paged template is an ordinary .paged or IDML document whose x-paged:template labels say which parts are fields and what a filler may change. The engine enforces it.

Tier: IntermediateIntermediateIIexplanationDraft

Reviewed against engine v0.74.2

A template is a document that knows which parts are open.

In short A template is an ordinary .paged or .idml document. Its policy lives in labels with the key x-paged:template: one on the document (what a filler may do everywhere, the order of the form) and one on each item that is a field or has its own permissions. A session has a role; a filler may change only what the policy permits, and the engine — not the UI — refuses everything else, from any caller. Fill a template in the editor's template-fill preset, through the embedding handle, or on a server with paged template.

How a template is stored

WhereLabelHolds
the document (designmap)x-paged:templatepermissions a filler has on every item (none by default), the form order, text-variable fields
a page itemx-paged:templatethe item's field definition, and permissions granted or denied on it

Both values use the envelope every x-paged: label uses, { "v": 1, "data": … }. An item's policy:

{
  "v": 1,
  "data": {
    "field": {
      "name": "headline",
      "kind": "text",
      "label": "Headline",
      "required": true,
      "constraints": { "maxLength": 30 }
    },
    "allow": ["text.style"],
    "deny": []
  }
}

Because the policy is document data in labels, it travels wherever labels do: .paged save and load, and IDML export and import. A label that cannot be read does not stop the document from opening: that item (or the document) then has no policy, which for a filler means nothing is permitted there.

The parts

  • FieldsIntermediateII· referencethe open parts: kinds, constraints, values, which kinds can be set today, and the module fields every built-in module contributes (a sheet's cell, a doc's paragraph, a drawing's colour).
  • Permissions and rolesProIII· referencethe permission vocabulary, how a filler's permissions are resolved, the three doors the engine checks, and the typed refusals.
  • Filling a templateIntermediateII· how-tothe form and field outlines in the editor, the template-fill and viewer presets, and filling on a server.

Making a template

An author makes a template in the editor's Template panel (paged.template):

  1. Take up authoring. Only the author role may write the policy; the panel offers to switch the session to it ("Author template") and back ("Stop authoring").
  2. Make a field. Select one item and choose its kind — text, image, visibility, or module content (one of the field kinds the loaded modules offer, with the module's definition as JSON) — and give it a name, a label, a group, help text, required, and for text a maximum length. Saving writes the item's x-paged:template label and gives the item the field's name, so the field can be addressed by name and the name survives an InDesign round trip. Remove field takes it off again.
  3. Grant more on the item, beyond what the field takes: format the text, move and scale the picture in its frame, move, resize, rotate, delete, show or hide, change the fill or the stroke.
  4. Set what a filler may do everywhere (the document's defaults): select any item, add and remove pages, add new items. Nothing is permitted by default.
  5. Preview as filler. The session switches to the filler role and the template behaves as a filler will see it: the form, the outlines, and the engine's refusals. Back to authoring switches back; the undo history stays, so an author's edit made before the preview can still be undone.

The panel lists the template's fields with their labels and kinds; a refused write shows under the field editor in words. Every change is one label write the engine checks like any other; a policy can also be written without the panel, through the setPluginMetadata mutation in an author session (for example through the embedding handle's client).

InDesign

  • Names. A field is addressed by its name. Give the item the same name in InDesign's Layers panel and the field can be addressed by it from outside (frame[name="headline"]); a name survives an InDesign save where an internal id may not.
  • Labels. The policy is stored in IDML item labels, which paged writes on export and reads on import.
  • XML tags. Many InDesign template workflows mark the editable parts of a layout with XML tags. File ▸ Open as template… reads them: a tagged text frame or story becomes a text field (on the first frame of its thread), a tagged rectangle, oval or polygon an image field, and a tagged range of text a field for that text in its story. The field takes the tag's name (-2, -3 for repeats), and the tag's label, maxLength and required attributes become its label and constraints. The dialog lists every field it would make, each with a checkbox, and every tag it skips with the reason ("it is on a parent page", "a line or a group is no kind of field", …); on a document that already has fields it marks each as new, already a field, or changed, and lists the fields no tag names any more. Applying is one undo step.
  • Writing tags. Make field tags a text or image field's item with a tag named after the field (with its label, maxLength and required as attributes), and Remove field untags it. paged writes XML tags on IDML export once the structure was edited, so the tags travel back to InDesign; an unchanged import still exports byte for byte. A tagged range is not yet enforced on its own — its field grants editing of its whole story — and templates made in paged have not yet been checked by opening them in InDesign.
  • On a server. paged template ingest <doc> -o <out> (the Node command line) does the same as Open as template: --names makes untagged items with a name fields too, and --placeholders turns plugin placeholders (Data Merge fields) into fields.

Template preflight

The Template panel's Problems section, shown to an author, lists what would break the template before it reaches a filler, and the field outlines mark the fields concerned:

CodeSeverityFound when
policyUnreadableerrorA template label cannot be read.
fieldUnnamederrorA field has no name, so no form or data can address it.
fieldDuplicateerrorSeveral fields share a name; a value would reach only one.
imageNotReplaceableerrorA picture field sits on an item that holds no picture.
textHasNoStoryerrorA text field sits on an item that holds no text.
requiredHiddenwarningA required field's item is hidden.
fieldOnParentPagewarningA field is on a parent page, where no filler reaches it.
linkMissingwarningA picture field shows a picture that is not in the package.

The findings are the engine's templateFindings collection. They are not the PDF exporter's checks, which paged preflight runs.

Catalogues

A template's own text, picture and visibility fields can be bound to data with paged.data: in the Bindings panel's Template fields section, bind each field to an expression over a query, choose one page per record or one page per group, and Make catalogue. The template page is repeated once per record or group and each copy filled, checked against the fields' required and maxLength (one refused value refuses the whole run); running it again replaces the copies. Scripts and the command line reach it through paged.data's typed commands (templateFieldTargets, bindTemplateField, runCatalogue).

The Template panel's This page section lets a filler copy the page and remove its copies — the pages of a catalogue — and nothing else; an author makes the first catalogue. Choice, text-run, data and module fields are not catalogue targets, and a page whose stories hold a table, an anchored object or a footnote cannot be repeated yet.

On this page