All articles

Templates

Bind fields to your data

Binding is the difference between a document and a template. A bound value is not typed; it points at a field, and each render resolves it against that render's record. One template, ten thousand correct documents.

Before you start

In the hosted app, binding fields needs the editor role or higher. Local mode has no roles.

You need data loaded: sample data, or, in the hosted app, live records from a data source. Weft opens with a sample sales quote loaded, each starter document brings its own sample, and a blank template starts with none. Open the data pill, the button in the bar directly above your document that names the data you are previewing (such as Full quote), to see what is loaded. Switch samples under Preview shape; in the hosted app, choose the template's data source under Render source and press Use live data to design against real records.

A saved template reopens with the sample data you last previewed it with. Weft remembers that in this browser rather than saving it with the template, so on another device or browser, or for a teammate opening the template for the first time, it opens with no preview data and the data pill reads No preview data. Paste data under View / edit sample JSON and press Apply, or load live records, so the canvas shows values and Weft can check your bindings against them.

You can bind against sample data and connect the real system later. Your bindings keep working as long as the real fields have the names you bound; any that do not are flagged.

Bind a single value

A value from your data is a field run: one piece of an element's text, beside fixed words. See Text runs.

  1. Select the element and open the properties panel with the button at the far right of the app bar (tooltip Show properties panel). ⌘. (Ctrl+. on Windows) works too.
  2. Find its runs: the Content panel of a heading or paragraph, a list's items, or a table column's Cell content.
  3. Press + Field. A chip marked ƒ appears at the end.
  4. Set the path on the chip. Type it, with suggestions from the loaded data, or — when a hosted template reads from a data source — pick from that source's fields.

The canvas shows the field's value straight away. A ⚠ on the chip means the path does not resolve in the loaded data, usually a typo.

For text that mixes fixed and bound content, such as "Invoice INV-2019 is due on 14 March", build the line out of runs: + Text for the fixed words and + Field where each value goes. Runs are added at the end; use ↑ and ↓ in a chip's ⋯ options to put them in order.

The Content card for a footer paragraph. Its runs are listed as chips: the text Private & Confidential, a separator dot, a field chip marked ƒ showing record.Firm.Name, a separator dot and the word Page, a Page # counter, the word of, and a Page count counter. Below are buttons to add Text, Field, Formula, Page # and Page count.

Bind a list

Tables and repeats bind to a list rather than a single value, and then repeat themselves.

  1. Select the Table or Repeat. A Repeat draws nothing of its own on the canvas, so select it from its row in the Outline.
  2. Under Source, set List path to the list — your line items, your transactions, your contacts. A new Table or Repeat already points at the first list it finds — in the hosted app, a saved template's data source first, otherwise the sample data.
  3. Inside it, bind fields of one item through the Binding name, which is item unless you change it: in a table over line items, item.Product prints each row's product. Fields of the whole record, such as record.QuoteNumber, still work inside.

This is why the Table block exists as its own kind: you describe one row, and the render produces however many the data has.

Lists can nest. A Repeat over orders can hold a Table or another Repeat over each order's line items. Inside the inner one, item means the line item. To reach the order as well — its number on every line — give the outer Repeat its own Binding, such as order: the inner list path becomes order.LineItems, and order.Number prints the order number. See Repeat element and Table element.

Calculated values

Not everything is stored. Totals, subtotals, line amounts and percentages are usually arithmetic over the record you already have.

Press + Formula and build the calculation in the chip's ⋯ options — quantity × unit price, subtotal + tax. The same calculation can sit inside a condition, so "when quantity × price is over 100" is expressible without leaving the editor. See Formulas.

For a column of numbers, use a total rather than computing it yourself: + Total in a table column's Footer / total, or in a grouping level's Subtotal row, gives a sum, avg, count, min or max over the list.

A missing value, a value that is not a number, or a division by zero makes a formula print nothing rather than breaking the render.

Formatting

Each field, formula and total has a format menu (tooltip Format) in its ⋯ options: Default, Text, Number, Currency, Percent, Date, Date & time or Time. The format belongs to the place the value prints rather than to the data, so the same field can print as £1,240.00 in one place and 1240 in another. See Format values.

A bound value can also carry a fallback: what to show when the field is empty. An explicit "—" reads better than a blank space, and it tells the reader the value was empty rather than that the document is broken. The properties panel has no control for setting one by hand; a fallback comes from a template Buddy produced.

Check what a value actually did

In the Flow view, point at a value from your data — a field, formula or total in a heading or paragraph, or a total in a table's footer row. A Trace button appears beside it (tooltip Where does this value come from?). Click it to open Where this value comes from, which lists, top to bottom:

  • Rendered — what is on the page.
  • Format — the format applied and the locale; it reads Formatted when a format was chosen and No format set when none was.
  • For a field, Value — the value before formatting, or a note that nothing was found (and, when the field has a fallback, that the fallback prints instead) — and Field, the path it came from.
  • For a formula, Value and Reads: each field the formula uses, with the data source it comes from, or "from your loaded data".
  • For a total, Total, then the operation, such as Sum, with the list it went through, then Rows: each row's value, with rows that added nothing marked skipped.
  • Data source and Connection — for a field or total, in the hosted app, the data source and connection behind the value; otherwise a note that it comes from the data you loaded.
A dialog titled Where this value comes from. It lists the rendered total, its currency format and locale, that it is a sum over the fee schedule, the four fee rows that were added up, and a note that the value comes from the data you loaded.

Use it whenever a number looks wrong. It answers "where did this come from?" directly instead of by inference — which matters most in exactly the documents where being wrong is expensive.

A value inside a Repeat or in a table's ordinary rows prints once per item, so Weft cannot tell which item you pointed at, and shows no Trace button there. Trace the column's total instead: it lists every row's value.

When a binding cannot resolve

Weft does not silently render a blank. In the Flow view, a binding that provably cannot resolve against the loaded data gets a dashed underline on the canvas and a card in the "things to check" dock at the bottom left, such as This field won't resolve or This list has no data. The same findings are listed in the check behind Preview PDF before you render — see Check before export.

The two usual causes:

  • The field does not exist — often a typo, or a field that exists on a different object than the one your data source pulls.
  • The sample does not have it — the binding is right for your real records, but the sample you are previewing lacks that field. Switch samples under Preview shape in the data pill, or, in the hosted app, press Use live data there, to check against real records.

With no preview data at all — a blank template, or a saved template opened in a browser that has none for it — Weft does not call every field a typo. The fields show empty, and one notice, No preview data yet, says so in the dock and in the check behind Preview PDF; load data from the data pill to see and check the bindings. In the hosted app, a field that the template's data source does not provide is still flagged.

When a mistyped field is close to one that exists, the card offers a button reading Use followed by that field's name. Every card about a block also offers Ask Buddy to fix, which hands that one problem to Buddy; the fix comes back as a proposal for you to review rather than being applied behind you. See Fix flagged issues.

What next