All articles

Elements

Conditional element

A Conditional holds a group of blocks and prints them only when a condition about your data holds: a late-payment notice when the invoice is overdue, a discount line when there is a discount. When the condition fails, those blocks print nothing at all.

Every element also has its own Show only when a condition is met setting (see Show only when). Use that to hide one element. Use a Conditional when several blocks share one condition, so you set it once.

Changing a template needs the editor role or higher in the hosted product; local mode has no roles.

Add one

Open the add-block menu (Add block at the top of the Outline, or the + that appears between blocks on the canvas in Flow view) and pick Conditional under Logic & Layout. It holds one paragraph, "Shown when the condition holds", and its condition is always true until you change it.

A Conditional can go anywhere a block can: the document body, inside a Section, in a column or grid cell, or inside a Repeat, where the condition is checked for each item.

A Conditional draws nothing of its own on the canvas, and when its condition fails for the sample data its blocks are not drawn either. Select it from its Conditional row in the Outline; expand the row to see its blocks under then. To add a block inside it, use the + between its blocks on the canvas, or select one of them and press Add block.

Properties

Select the Conditional and open the properties panel with ⌘. (Ctrl+. on Windows) or the panel button at the far right of the app bar (tooltip Show properties panel).

Condition

The first line reads the condition back in words, such as "Show when Discount Percent is greater than 0." Below it is the condition editor: a tree of parts, each with a menu that sets its kind.

PartWhat it does
FieldA value from your data, entered as a path such as record.Status. On its own it holds when the field is filled in (see How conditions are judged, below)
Fixed valueA value you enter, typed as Text, Number, True / False or Empty
ComparisonCompares two parts with =, ≠, >, ≥, < or ≤
And / Orand needs every condition listed, or needs any. + Add condition adds one; ✕ removes one
NotHolds when the condition inside it does not
CalculationAdds, subtracts, multiplies or divides two parts (+, −, ×, ÷), such as quantity × unit price inside a Comparison

To build "Status is Overdue":

  1. Set the top part to Comparison.
  2. Set its first part to Field and enter the path, such as record.Status.
  3. Choose =.
  4. Set the second part to Fixed value with the type Text, and enter Overdue.

If a field path does not resolve in the loaded data, Weft warns under it and may offer a button reading Use followed by a likely path. For arithmetic, see Formulas.

Conditional

The panel every element has (see Shared element properties). Its Show only when a condition is met is checked before the Conditional's own condition: when it fails, nothing inside prints. Unlike the Condition above, its line reads "Shown when …". A new one starts as a stand-in field that is not empty text, which holds, so ticking it leaves the Conditional's blocks in place while you build the real condition.

What prints when the condition fails

Nothing: the blocks inside take no space and leave no gap.

A Conditional can also hold a second set of blocks that prints instead when the condition fails; the Outline lists them under else. You cannot add this second set by hand, but Buddy can include one when it generates or edits a template (see Ask Buddy to edit). Once it exists, you edit those blocks like any others. Deleting the last block under else removes the set.

How conditions are judged

  • A missing field counts as Empty, so "field = Empty" holds when the field is missing.
  • = and ≠ compare exactly, type included: a Number 5 does not equal a Text 5, and Overdue does not equal overdue. Match the fixed value's type and spelling to the field.
  • >, ≥, < and ≤ do not hold when either side is missing. A Calculation with a missing or non-numeric side, or a division by zero, counts as missing.
  • A Field on its own fails when the field is missing, empty, zero, false, or a list with no items. So a Conditional whose condition is just a list's field can print a heading and a Repeat only when the list has items.

How it differs from Show only when

AspectConditional elementShow only when
CoversAny number of blocksOne element and everything inside it
Content when falseIts else blocks, if anyNone
Revealed by Show hidden blocksNoYes, except inside a Repeat
Box, spacing, page-break settingsNoneThe element's own

Show hidden blocks is in the data pill (the button above the document that names the data you are previewing, such as Full quote), in Flow view. To see blocks a Conditional is holding back, preview with data for which its condition holds: switch the sample under Preview shape in the same menu.

Good to know

  • A Conditional has no background, border or keep-together settings. To show a styled or kept-together group only sometimes, use a Section with Show only when a condition is met (see Section element).
  • Inside a Repeat, the condition can test the current item, such as item.Status.
  • A Conditional always holds at least one block under then: Weft will not delete or drag out the last one, so delete the Conditional instead. Deleting it asks you to confirm.