Skip to main content

Use liquid filters to display contact insight data information in a email

Filters you can use on your Liquid output to display Insight data information.

Written by Gareth Burroughes

Add Insight data information to your Liquid markup block:

  1. Use Liquid to select a specific collection:
    ​{% assign orders_data = contact.insight.orders | sort: 'purchase_date' %}
    This snippet uses the contact scope, selecting Insight data for the orders collection:
    ​contact.insight.orders
    This sorts it by the purchase date:
    ​sort: 'purchase_date'
    ​

  2. Add orders_data:
    ​{% for orders in orders_data | limit:10 %} ...{% endfor %}
    orders_data is a list of orders ordered by purchase_date.
    ​Learn more in Filter Liquid outputs.
    ​

  3. Enter the products field:
    ​{% assign products_data = orders.products | sort: 'price' | reverse %}
    ​

  4. The products field is another list, so it needs to be looped through:
    ​{% for products in products_data %} ... {% endfor %}
    ​

  5. Show specific products data:

    <p>product price: ##{{ products.price }}</p>

Full code snippet example

{% assign orders_data = contact.insight.orders | sort: 'purchase_date' %}
{% for orders in orders_data | limit:10 %}
{% assign products_data = orders.products | sort: 'price' | reverse %}
{% for products in products_data %}
<p>product name: ##{{ products.name }}</p>
<p>product price: ##{{ products.price }}</p>
{% endfor %}
{% endfor %}

You can also include:

<p>##{{ orders.purchase_date | date }}</p>
{% assign orders_data = contact.insight.orders | sort: 'purchase_date' %}
{% for orders in orders_data | limit:10 %}
<p>##{{ orders.purchase_date | date }}</p>
{% assign products_data = orders.products | sort: 'price' | reverse %}
{% for products in products_data %}
<p>product name: ##{{ products.name }}</p>
<p>product price: ##{{ products.price }}</p>
{% endfor %}
{% endfor %}

Did this answer your question?