Conditional content and loops in templates

3 December 2025 · 6 min read · Nextarp B.V.

A single template rarely fits every case. One customer has a discount, another does not; one contract has three signatories, another has one. Conditions and loops are how one template produces thousands of correctly tailored documents.

Conditions: show and hide

A condition wraps content that should appear only when the data warrants it - a late-payment clause when a balance is overdue, a VAT section only for EU customers. Author it with a simple marker around the block; at generation time the block is kept or dropped. This beats leaving blank labels or placeholder text.

Loops: repeat over lists

A range repeats its content once per item in a collection - line items on an invoice, employees on a report, signatories on an agreement. Keep the range tight around exactly the content to repeat, and let a Word table row be the unit that multiplies.

Nesting

Real documents nest: an order containing line items, each with sub-charges. Ranges within ranges handle this, provided each level maps cleanly to your data model's relationships.

Guardrails

  • Always define the empty case - what shows when a list has zero items.
  • Avoid deep nesting where a flatter data shape would do.
  • Preview against data that exercises each branch before publishing.

Done well, conditional logic is invisible: every recipient simply gets the document that is right for them.

Related articles

DocsNG is the free, self-hostable platform for generating, signing and verifying documents. Get DocsNG or try the live demo.

← Back to the blog