Use objects in liquid
Learn how to reference objects and relationships using liquid.
Currently, you can only reference object and relationship liquid in messages, not workflow actions.
Try generating liquid with AI
We know that liquidA syntax that supports variables, letting you personalize messages for your audience. For example, if you want to reference a person’s first name, you might use the variable {{customer.first_name}}
. is complicated, even moreso when you need to reference objects, relationships, and people in the same message. To make things easier, we built a tool that uses AI to generate your message and liquid for you.
This is an experimental feature. You can enable by going to the icon in the upper right corner of your workspace and clicking Experimental Features. Then you can click Generate with AI in campaigns triggered by changes to objects or relationships to generate your message and associated liquid tags.
We’ll use the object name and relationship attribute names to try and generate your message. You can copy the output into your message and continue refining it to better fit your needs.
Like other AI-based chat tools, you can refine your prompt to get the results you want. For instance, if you want to reference a specific attribute in the subject line of an email, you might modify the prompt with “add attribute_name to the subject line.” You can continue to refine your message after you copy the results into your message.
Reference trigger data
Currently, you can only reference object and relationship liquid in messages, not workflow actions.
You can trigger campaigns based on changes to objects and relationships, so we made it possible for you to use liquid that targets the trigger object or relationship data. You can reference trigger data for object and relationship-triggered campaigns using {{trigger.<object_type>.<attribute_name>}}
.
For instance, if you have an object type of “Online Classes” and set up a campaign to trigger when you update a class, you could craft an email like the following:
Liquid Syntax | Rendered Liquid |
---|---|
Hi {{customer.first_name}} ! We just added a syllabus to {{trigger.online_class.name}} . | Hi Jeff! We just added a syllabus to Calculus 1A. |
See the liquid examples below for more use cases.
New to JSON?
Objects in Customer.io use JSON dot notation; if you’re not familiar with JSON, we have a quick primer to help you understand how it works.
Relationship-triggered campaigns
You can use the following liquid when a relationship triggers a campaign:
{{trigger.relationship.<attribute_name>}}
{{trigger.<object-type>.<attribute_name>}}
{{trigger.customer.<attribute_name>}}
Recall that a relationship-triggered campaign can have an audience that is different from the person with the relationship that triggered a campaign. You have the ability to reference both people using liquid. For instance:
Liquid Syntax | Rendered Liquid |
---|---|
Hi {{customer.first_name}} ! {{trigger.customer.first_name}} just joined your {{trigger.online_class.name}} class. | Hi Jeff! Ali just joined your Calculus 1A class. |
{{customer.first_name}}
refers to the audience/recipient of the message, and {{trigger.customer.first_name}}
refers to the person with the relationship that triggered the campaign.
Object-triggered campaigns
You can use the following liquid when an object triggers a campaign:
{{trigger.<object-type>.<attribute_name>}}
Reference non-trigger data
Currently, you can only reference object and relationship liquid in messages, not workflow actions.
We know this isn’t the easiest to use - thanks for bearing with us! We plan on improving this experience soon.
If you’ve read the above, you may be wondering how to reference object data when an object or relationship is NOT the trigger for a campaign. You can, for instance, check if someone is related to an object or list specific attributes across all related objects in a type.
You cannot reference more than 10 objects of the same type
If a person is related to 11 classes, {{objects.online_classes}}
will render based on the date each object was created, NOT when the person became related to the object. This would mean that if you just related the oldest online class to a person with relationships to 10 other classes, then this class would not render in the list because the 10 other classes were created more recently.
The following examples imagine that you relate people to “Online Classes”.
Check if a person is related to objects
{% if objects.online_classes | size == 0 %}
This person doesn't have any classes.
{% else %}
This person is enrolled in at least one class.
{% endif %}
Show information for every object related to a person
{% for class in objects.online_classes %}
Your {{class.name}} begins on {{class.date}} at {{class.time}}.
{% endfor %}