Wit

Conditionals

A conditional shows content only when the data agrees — order states, draft banners, sale prices. Statements sit in parentheses, so logic reads as an aside.

Compare with is

source
#order: { status: shipped, items: 3 } !!

(if @order.status is shipped)
Your order is on its way.
(else)
We are packing your order.
(end)
result

Your order is on its way.

<p>Your order is on its way.</p>

is is the only operator; the right side is a value. There is no not, and, or, < or contains — a header other than (if @path …) is E_MALFORMED_STATEMENT. Numbers compare by value, so (if @order.items is 3) matches.

Test truthiness

Drop is to test whether a value is present and truthy. Falsy is: missing, empty, false, null, 0, an empty record and an empty collection. Everything else is truthy. Simple definitions can be tested too.

source
#gift: false !!
#order: { items: 3 } !!

(if @order.items)Three items. (end)(if @gift)Gift-wrapped. (end)Thanks!
result

Three items. Thanks!

That renders Three items. Thanks!

Else and nesting

(else) is optional, either branch may be empty, and ifs nest, each with its own (end):

source
#lamp: { lit: true, oil: low } !!

(if @lamp.lit)
(if @lamp.oil is low)
Lit, but refill the oil tonight.
(else)
Lit and fuelled.
(end)
(end)
result

Lit, but refill the oil tonight.

That renders Lit, but refill the oil tonight.

Inside a definition

Test a parameter with (if ::name::):

source
#price(amount, sale)
£::amount::(if ::sale::) (on sale)(end)
price#

Soup @price(amount: 12, sale: true), bread @price(amount: 9, sale: false).
result

Soup £12 (on sale), bread £9.

That renders Soup £12 (on sale), bread £9. A definition cannot sit inside a conditional — E_CONDITIONAL_DEFINITION — so put the condition inside the definition, as here.

Inline statements

Written inside a sentence, a statement stays inline. It may follow a space, punctuation, a reference or another statement's ), and its (else) and (end) may touch a word: (if @x)Done(end).

Errors

  • E_UNCLOSED_STATEMENT — no (end).
  • E_MALFORMED_STATEMENT — an operator other than is, or a subject that is not @path.
  • E_CONDITIONAL_DEFINITION — a definition inside a branch.

See also

Iteration · Data · Faceted content · Gotchas