Skip to main content

Collection Operators

When we need to work with collections, these operators will help with your markdown.

List of Operators

{{ isEmpty }}

Inline, subexpression, or block helper that returns true (or the block) if the given collection is empty, or false (or the inverse block, if supplied) if the collection is not empty.

Params

  • collection
  • options
  • returns

Example

<!-- array: [] -->
{{#isEmpty array}}AAA{{else}}BBB{{/isEmpty}}
<!-- results in: 'AAA' -->

<!-- array: [] -->
{{isEmpty array}}
<!-- results in: true -->

{{ iterate }}

Block helper that iterates over an array or object. If an array is given, .forEach is called, or if an object is given, .forOwn is called, otherwise the inverse block is returned.

Params

  • collection 0: The collection to iterate over
  • options
  • returns

Example

<!-- iterate over all line items on the deal -->
{{#iterate deal.skus}}
<!-- when the line item title is "Discount" include this text -->
{{#eq this.title "Discount"}}
A one-time discount is offered on this deal will not carry through future
renewals.
{{/eq}}
{{/iterate}}