Skip to main content
Elemental has four control flow properties:
  • if - Conditionally render elements based on data or conditions
  • loop - Repeat elements for each item in an array
  • ref - Reference elements to check their visibility or properties
  • channels - Show elements only on specific channels
All four are optional, available on every element, and can be combined on the same element.
Control flow properties are evaluated at render time using Handlebars expressions. You can read message.data, message.to.data, and other message context.

If

The if property renders an element only when a Handlebars expression is truthy. Otherwise the element is skipped. When to use:
  • Show different content based on user type, subscription status, or feature flags
  • Display elements only when certain data exists
  • Create personalized experiences based on user context
  • Hide elements that aren’t relevant to the current recipient
Applies to: All Elemental elements Basic Example
Realistic Examples Conditional welcome message based on user type:
Show elements only when data exists:
Structured conditions The if field also accepts a structured condition array: one or more condition groups evaluated at render time. The element renders if any group matches, so groups are OR’d together. Within a group, conditions combine using the group’s logical_operator. Supported property namespaces (dot-paths only): Supported operators: Design Studio labels these operators in prose, and three do not match their JSON key. The editor builds the same object either way. This is the mapping: The other seven read as their key: equals, is greater than, is less than, contains, does not contain, is empty, is not empty. There is no empty structured condition. Delete a group’s last condition and the group goes with it. Delete the last group and the if field is removed rather than left as [], so an empty array is not the way to express “no conditions” and an element carrying one is malformed. Single group (all conditions AND’d):
Multiple groups (OR between groups):
Unary operator (no value needed):
Using refs to check element visibility:
String if and structured if are mutually exclusive on the same element. Use one or the other. String expressions remain fully supported.

Ref

The ref property names an element so other elements can reference it. A referenced element exposes its properties plus visible, which says whether it rendered. When to use:
  • Check if another element was rendered before showing related content
  • Create dependencies between elements
  • Build complex conditional logic based on element visibility
  • Access element properties from other elements
Applies to: All Elemental elements Note: An element can only reference elements defined earlier in the elements array. Basic Example
Realistic Example Show follow-up content only if initial element is visible:

Loop

The loop property renders an element multiple times, once for each item in an iterable data source (typically an array). When to use:
  • Display lists of products, orders, notifications, or other array data
  • Create dynamic content that adapts to variable-length data
  • Build repeating patterns like product cards or notification items
  • Iterate over nested data structures
Applies to: All Elemental elements Loop variables:
  • $.item - The current item in the iteration
  • $.index - The zero-based index of the current iteration
Basic Example
Realistic Examples Product list with nested data:
Using $.index for item numbering:
To show a 1-based item number, pass $.index to the add :
This outputs “Item 1”, “Item 2”, and so on, instead of starting at zero.

Channels

The channels property renders an element only on the channels you list. Use it to show different content on email, SMS, push, and other channels. When to use:
  • Show detailed content in email, concise content in SMS
  • Display channel-specific formatting or elements
  • Customize content per channel while maintaining a single template
  • Hide elements that don’t work well on certain channels
Applies to: All Elemental elements Valid channels: email, push, direct_message, sms, or provider-specific channels like slack, discord, etc.
For a fully different content structure per channel, use .
Basic Example
Realistic Examples Channel-specific content:
Hide complex elements on SMS:
Combining Control Flow Properties You can combine multiple control flow properties on the same element:
Evaluation order:
  1. channels - Element must match current channel
  2. if - Condition must evaluate to truthy
  3. loop - Element is repeated for each item (if present)
  4. ref - Element is registered for reference (if present)

Best practices

  • Use if for conditional content: Show/hide elements based on data or user context
  • Use loop with group: Wrap looped elements in a group for better organization
  • Reference order matters: Elements must be defined before they’re referenced
  • Test with real data: Control flow expressions are evaluated at render time, so test with realistic data structures
  • Combine with locales: Use control flow with for fully dynamic, multi-language notifications
  • Channel considerations: some elements (like columns) may not render well on all channels