Control Flow
In addition to their standard properties, Courier elements have a few additional properties that allow you to apply control flow logic to the element.
Each control flow property is optional.
If
Conditionally renders an element.
Applies to: text
, meta
, channel
, group
, action
, image
.
Examples
Ref
Names an element for reference by other elements. Referenced elements provide access to:
- Their properties
- A
visible
property (true
if rendered,false
otherwise)
Note: An element cannot reference another before it is defined.
Applies to: text
, meta
, channel
, group
, action
, image
.
Example
Loop
Renders an element multiple times based on an iterable data source.
loop
must evaluate to an iterable data source$.item
refers to the current item in the iteration$.index
provides the current index
c
When using $.index
in loops, you can easily display a 1-based item number by using the add
handlebar helper:
This will output “Item 1”, “Item 2”, etc., instead of starting from zero.
Applies to: text
, channel
, group
, action
, image
.
Example:
Full message payload:
Expanded result:
Channels
Selectively renders an element based on the current channel.
Valid channels: email
, push
, direct_message
, sms
, or provider channels like slack
.
Applies to: text
, meta
, channel
, group
, action
, image
.