Wit

Composing constructs

The primitives stack: data feeds loops, loops feed conditions, definitions take data as parameters and use other definitions. This page shows the common seams and the few places they do not join.

Loop, then filter

Loop a collection of records and gate each item with a condition:

source
#shifts: [
  { name: Ada, awake: true }
  { name: Bo, awake: false }
  { name: Cy, awake: true }
] !!

@ul
(each @shifts as s)
(if @s.awake)
(li @s.name is on watch. li)
(end)
(end)
ul@
result
  • Ada is on watch.
  • Cy is on watch.
<ul><li>Ada is on watch.</li><li>Cy is on watch.</li></ul>

Data into a definition

A data path is a parameter value like any other, by position or by name:

source
#source: { author: Simone Weil, work: Gravity and Grace } !!

#cite(author, work)
::author::, _::work::_
cite#

As @cite(@source.author, @source.work) has it.
result

As Simone Weil, Gravity and Grace has it.

That renders <p>As Simone Weil, <em>Gravity and Grace</em> has it.</p>. Emphasis around a placeholder, as in _::work::_, applies to the inserted value.

Definitions inside definitions

A definition body may use other definitions and data; a parameter value may carry emphasis:

source
#price: 12 !!
#menu-line(dish)
::dish:: — £@price
menu-line#

@menu-line(dish: _Hake_ with samphire)
result

Hake with samphire — £12

That renders <p><em>Hake</em> with samphire — £12</p>.

Seams that do not join

  • No definitions inside statements. A definition inside (if …) or (each …) is E_CONDITIONAL_DEFINITION. Put the condition inside the definition, and test a parameter with (if ::name::).
  • No statements inside raw bodies. A @@style body is verbatim, so a loop there is text and its {{t}} is E_UNRESOLVED_REFERENCE. Interpolate named fields instead (see Literal & raw nodes).
  • !! closes value blocks only. It ends a #name: definition or a @name(…): use; anywhere else it is two exclamation marks, and an inner node still needs its own close.
  • A reference cannot be conditional. Pick a different root file per edition (see Faceted content).

See also

Iteration · Conditionals · Interpolation & captures · Derived content · Gotchas