Conditions
A section or element with a condition only appears when the condition is true. A condition is what goes between
{% if and %} in Liquid:
- A value on its own:
customer.vip. Every value is true exceptfalseand no value at all, so an empty text and0are true too: writecustomer.notes != blankto check for text. - Comparisons:
==,!=,>,<,>=,<=, andcontainsfor text and lists:tags contains "rush". andandor, without parentheses. Liquid reads them from right to left:a and b or cmeansa and (b or c).- A list’s size:
line_items.size > 0.
Conditions can’t use filters. A condition on a repeating section
goes on the repeat section, not its item, and is checked once. Elements inside the item can have their own
conditions, which can read the entry: item.discount > 0.
Examples
Section titled “Examples”A “VIP” badge that only shows for VIP customers:
{ "id": "vip_badge", "type": "text", "x": 440, "y": 0, "width": 100, "height": 20, "condition": "customer.vip", "style": { "background": "#ffd966", "radius": 4 }, "content": { "type": "doc", "content": [ { "type": "paragraph", "attrs": { "align": "center" }, "content": [ { "type": "text", "text": "VIP", "marks": [{ "type": "bold" }] } ] } ] }}A notes section that’s left out when there are no notes:
{ "id": "notes", "type": "stack", "direction": "vertical", "condition": "notes != blank", "elements": [ { "id": "notes_text", "type": "text", "content": { "type": "doc", "content": [ { "type": "paragraph", "content": [{ "type": "field", "attrs": { "expression": "notes" } }] } ] } } ]}A page break before the terms, only for large orders:
{ "id": "terms_break", "type": "page_break", "condition": "total > 10000 and status == \"approved\""}