Written by Drip

Global Variables with Drip Content Snippets

How to create massively dynamic content and hundreds of unique emails with minimal code and time.

To start with, if you don’t know what Drip is – Drip (drip.com) – a marketing automation system – collecting data, sending emails and automation workflows which let you do a whole bunch of great things. Drip uses the Shopify syntax Liquid for personalisation, which in my opinion puts it ahead of many of the other competitors.

What is this and why is this useful?

So this “global variables” trick came about because I needed a way to create over 100 unique emails in pretty much zero time.

Drip recently introduced a feature called Content Snippets. Content snippets allow you to save a block of content and then use that content in any email where you’d like it to appear.

One thing I love about content snippets is you can store a lot of liquid in them, you have a central place to update content and data on many emails. A few weeks ago, I discovered you can do something really powerful with content snippets. You can set/assign variables inside of a snippet, and use them out. It’s probably best if I just show you how it works:

First we create a snippet called “about_mike” and inside that, we set a variable called “mood” to “excited”:

{% assign mood = "excited" %}

Now, goto an email and insert your snippet, then you can use the mood variable after the snippet, eg:

{{snippets.about_mike}}
{{mood}}

So, I’ve been calling them global variables, you might have a better name for it. ?

So why is this so great?

Well if you go back to the snippet, and add a condition.

{% if subscriber.tags contains "purchased my cheap course" %}
  {% assign mood = "happy ?" %}
{% elsif subscriber.tags contains "purchased my expensive course"%}
  {% assign mood = "excited ?" %}
{% else %}
  {% assign mood = "sad ?" %}
{% endif%}

Then the email template just looks like this:

{{snippets.about_mike}}
I'm so {{mood}}.

So this is a really basic example, but this can be really handy for things like event details, course content, product details etc.

Instead of having all of this liquid in your emails, and needing to update all of your emails when something changes, you just have one content snippet.

I’ve used this trick a few times now, and this is why it’s the best:

  • You can set a massive list of variables inside of a snippet and set them based on the values of a subscribers custom fields, tags or any other data you can access with liquid conditions.
  • You keep conditions like “if this equals that show this” out of your email templates.
  • This helps you create massively dynamic content with minimal liquid code in your emails.
  • Use one set of variables in as many emails as you like, and easily update them all from one place.

How about another example, to emphasise the usefulness?

1 – Setup a new content snippet. I called this one project_variables

2 – Set the variables. We’re setting city name, location and date variables based on a subscribers next event custom field. So, if someone buys a ticket for Sydney, later in an automation workflow or bulk op, we might set their next_event field to “project-sydney”. Then in our email to them about the event, we call the snippet with the event details and we check which event they’re going to, like this:

{% if subscriber.next_event = 'project-sydney' %}
  {% assign city_name = 'Sydney' %}
  {% assign event_location = 'Sydney Harbour Bridge' %}
  {% assign event_date = '2018-12-28' %}
{% elsif subscriber.next_event = 'project-brisbane' %}
  {% assign city_name = 'Brisbane' %}
  {% assign event_location = 'Southbank' %}
  {% assign event_date = '2018-12-29' %}
{% endif %}

3 – Minimise the snippet code, strip-out line breaks and spaces between liquid, so it looks like this and place it into a snippet:

{% if subscriber.next_event = 'project-sydney' %}{% assign city_name = 'Sydney' %}{% assign event_location = 'Sydney Harbour Bridge' %}{% assign event_date = '2018-12-28' %}{% elsif subscriber.next_event = 'project-brisbane' %}{% assign city_name = 'Brisbane' %}{% assign event_location = 'Southbank' %}{% assign event_date = '2018-12-29' %}{% endif %}

 4 – Insert the content snippet into an email.

{{ snippets.project_variables }}

5 – Use the variables in an email:

{{ snippets.project_variables }}
We'll see you in {{event_city}} this {{ event_date | date: "%A" }}

That is it. Pretty simple, powerful, useful!

So, you can use this trick in images, subject lines, pretty much everywhere! If you use it in subjects, make sure you include the snippet at the start of your subject.

Make sure you test everything!

Last modified: February 2, 2020