Skip to content
Docs

Workflows

Logic in text

Show part of a message only sometimes, repeat a line for each item in a list, or work out a value first.

Text fields can do more than fill in a value. Between [% and %], you can show part of a message only sometimes, repeat a line for each item in a list, or work out a value first. It works like Jinja templates, with different brackets.

The conditions and values inside are expressions, so use variable names on their own and put text in quotes.

Show text only sometimes

Hi {full_name},
[% if plan == "gold" -%]
As a Gold member, your delivery is free.
[% endif -%]
Thanks for your order!

For a Gold member this sends all three lines. For anyone else it sends only the first and last.

To choose between several messages, add elif and else:

[% if plan == "gold" %]Free delivery[% elif plan == "silver" %]Half-price delivery[% else %]Delivery from £3.99[% endif %]

Every if needs an endif.

Repeat a line for each item

for repeats its text for each item in a list – such as the orders from a Send API or the rows from an SQL Query:

Your orders:
[% for order in orders -%]
- {order.id}: {order.status}
[% endfor %]

With two orders, this sends:

Your orders:
- A1: shipped
- B2: pending

Inside a loop, _loop says where you are:

WriteGives
{_loop.index}The item’s number, starting at 1
_loop.firstTrue for the first item
_loop.lastTrue for the last item

For example, [% for tag in tags %]{tag}[% if not _loop.last %], [% endif %][% endfor %] sends VIP, Wholesale.

A loop over an empty list sends nothing. To say so, put the loop in an if:

[% if orders %]Your orders:
[% for order in orders %]- {order.id}
[% endfor %][% else %]You have no orders yet.[% endif %]

Work out a value first

set saves a value to use further on in the same text:

[% set count = _.len(orders) %]You have {count} orders.

The value only lasts for that text. To keep it for later actions, use Set variable.

Change a value with a filter

A function can also go after the value, with | – {name|upper} is the same as {_.upper(name)}. Only the _. functions work as filters.

Line breaks and notes

  • A tag on its own line leaves a blank line behind. End it with -%] instead of %] to remove the line break after it, as in the examples on this page.
  • Text between {# and #} is a note for your team. It’s never sent.

What’s different from Jinja

If you know Jinja, these work differently:

In JinjaIn Proto
{{ name }}{name}
{% if … %}[% if … %]
loop.index_loop.index
Filters such as default, title, length and joinOnly the _. functions, such as upper, lower and len
for … elseNot supported – use an if round the loop

A mistake – such as a missing endif or a filter Proto doesn’t have – means the whole text is sent exactly as you wrote it. Check new text in the AI Agent tester.

Stuck? Ask Advisor in the Proto dashboard, or contact us.

© Proto