Liquid and variables

Every email can use Liquid to fill in names, plans, links, and anything else you know about the person. In the email editor, click {x} to pick a variable, or type it.

What you can use

VariableWhat it holdsWhere
{{ person.properties.first_name }}Any person propertyBroadcasts and automations
{{ event.properties.plan }}A property of the event that started the automationAutomations with an event trigger
{{ variables.reset_link }}Values your code sends, or values earlier steps savedTransactional emails and automations
{{ unsubscribe_url }}The person's link to the preferences pageMarketing emails. See unsubscribes.

A transactional email can't read person properties. Your code sends everything it shows.

Add a default

A property can be missing for some people. Add a default:

liquid
Hi {{ person.properties.first_name | default: 'there' }},

Use single quotes inside Liquid. A double quote inside a link's href ends the address early and breaks the link.

Properties that start with $

Use brackets and single quotes:

liquid
{{ person.properties['$email'] }}

{{ person.properties.$email }} fails, and the email doesn't send.

Show something to only some people

Wrap it in an if:

liquid
{% if person.properties.plan == 'pro' %}
Thanks for being on Pro.
{% endif %}

In the email editor, you can do the same for a whole block: open Who sees it, pick Show only when…, and fill in Only if.

Filters

Filters change a value before it shows, such as upcase, capitalize, date, and truncate:

liquid
Your trial ends on {{ person.properties.trial_ends_at | date: '%B %-d' }}.

PostHog adds a currency filter, which takes a currency code, a locale, or both:

liquid
Your total is {{ variables.total | currency: 'EUR' }}.

The Liquid docs list the standard filters. PostHog turns off the filters that take an expression, such as where_exp and group_by_exp.

Show personal stats

To send each person their own numbers, such as a yearly recap, save the numbers as person properties before you send. Save each one as a plain number, such as 42 for 42%, not as text such as "42%". When a plan has no limit, skip the percentage instead of dividing by zero. Then show them in a broadcast with a Custom HTML block:

HTML
{% assign used = person.properties.plan_used_percent | default: 0 | plus: 0 %}
{% assign bar = used | at_least: 0 | at_most: 100 %}
<table role="presentation" width="100%" cellpadding="6" style="border-collapse: collapse;">
<tr>
<td>Projects created</td>
<td align="right"><strong>{{ person.properties.projects_created | default: 0 }}</strong></td>
</tr>
<tr>
<td>Reports shared</td>
<td align="right"><strong>{{ person.properties.reports_shared | default: 0 }}</strong></td>
</tr>
<tr>
<td colspan="2">
Plan used: {{ used }}%
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background: #e5e7eb;">
<tr>
<td width="{{ bar }}%" style="background: #1d4aff; height: 8px; font-size: 0;">&nbsp;</td>
<td style="font-size: 0;">&nbsp;</td>
</tr>
</table>
</td>
</tr>
</table>
<p><a href="https://app.example.com/reports/yearly">See your full report</a></p>
  • The bar is a table cell with a width, because many mail apps ignore CSS on div elements.
  • plus: 0 turns the property into a number, so the label and the bar start from the same value. Only the bar is limited: at_least and at_most keep it between 0 and 100% when someone is over their plan.
  • The numbers are part of the email, so you don't need to host a private image.
  • For a file, such as a PDF report, link to it. Put it behind the person's login in your app, or use a signed link from your own storage that expires. Add data-ph-no-track and data-ph-no-utm to a signed link. A click then doesn't save its address in engagement events, and no UTM tags break its signature. Marketing emails can't carry attachments.

When it goes wrong

ErrorFix
TokenizationError: unexpected characterReplace curly quotes, often pasted from a document, with straight single quotes.
expected "\|" before filterA property starts with $. Use person.properties['$email'].
A blank where a name should beThe person doesn't have the property. Add a default.

If Liquid doesn't render, the email doesn't send. Before you go live, pick a real person in Preview as, and send yourself a test.

For the size and send limits on each email, see email and automation limits.

Still have questions?

Was this page useful?