Create Dynamic Content with Liquid Syntax


This article applies to:

Dynamic content is exciting new functionality that enables powerful customization of marketing content. With dynamic content, you can send an email to a group of people with HTML formatted text displayed based on the recipients’ tags or field values. 

You may be thinking, that sounds like merge fields or decision diamonds. Well, it is like merge fields but instead of static content we can input dynamic content and it can replace the need for decision diamonds in an Advanced Automation that route people into different email sequences. Currently, this functionality is available in Broadcast emails and Advanced Automation email templates. Also, Dynamic content is available in Keap “simple email broadcast” tool and the Keap Advanced Email tool.

For more information check out these online resources: this article at Monkeypod Marketing, this article at Shopify, and this one at Github

Dynamic Content is a powerful feature of our software. However, it requires knowledge of the Ruby programming language. If you are unfamiliar with Ruby, we recommend learning more about the language before trying this feature. 

Keap Technical Support will not assist with programming or debugging your Dynamic Content.

Getting started

I’m a new user, what is a simple way to immediately benefit from dynamic content? 
If any of your contacts don’t have a first name in the contact record, and you are using merge fields or decision diamonds to send custom communications, it can result in those contacts seeing code or something confusing in the name field. This is a poor experience for them and embarrassing for you. With Dynamic Content, you can define a default value for first name like “friend” to ensure all contacts have a similar and positive communication. Contacts that have their name in the contact record name field will see their name in custom communications, and contacts without a name in the field will see the word friend or whichever term that you choose.


FAQ

What is Liquid? 
Liquid is a template language that enables dynamic content, somewhat similar in concept to merge fields but instead of static content we are able to input dynamic content in fields such as HTML formatted text and images.

Is dynamic content available in Keap or Infusionsoft? 
Yes, dynamic content is available in all versions of our software.

Does dynamic content work with custom fields? 
Yes, it works with all fields. 

Where can I use dynamic content in my app? 
If you are versed in Liquid syntax, then you can create dynamic content anywhere merge fields are used in the app.

What kind of dynamic content can I use? 
HTML formatted text, hyperlinks, and images. 

How can I learn more about Liquid and dynamic content? 
Review Shopify’s documentation for Liquid. This site provides the rules that define how to apply the Liquid programming language.

What can Keap Support help me with? 
At this time, our support team can help with the basics of the dynamic content editor. And if bugs are found, we will escalate to our product team. 


Liquid syntax

Liquid is a template language created by Shopify and written in Ruby. It is now available as an open source project on GitHub, and used by many different software projects and companies. Liquid is the backbone of all Shopify themes, and is used to load dynamic content to the pages of online stores. (Source: https://help.shopify.com/en/themes/liquid).

Designers and developers can use template language to combine static and dynamic content to populate pages with data from a Shopify store. Static elements are written in HTML and dynamic elements are written in Liquid.  

Keap's Broadcast Email and Advanced Automation Builder's email are where Liquid syntax is currently available for use.

For more information on Liquid syntax please see the open source documentation on Shopify's Page.

Prior to Liquid Content, your automation might look something like this...

After, your automation may look like this: 

Double clicking on the Dynamic Content icon reveals this


Liquid code basics

How Keap implemented the feature:

Because some merge fields are immediate, while some are sensitive to the time which an automation might occur, we’ve designed two distinct phases of how liquid will execute.

  • Phase 1 - Resolves at time of Advanced Automation publish. Looks like this {{ merge field }}
  • Phase 2 - Resolves at time of automation execution. Looks like this [[ merge field]]

The best way to explain this is with today’s date.
{{ today.date_and_time }}

If I were to include this in an email within an automation and I published the automation today, it would contain the date the automation published.

However, if I were to use [[ today.date_and_time]] in the email, it would use the date and time that the email was sent. If the Advanced Automation published last week, but this email was sent yesterday, it would merge yesterday’s date and time.


Objects
  • Tell Liquid where to show content
  • Denoted by double curly braces: {{ and }} or [[ and ]]
Operators
  • ==    equal to
  • !=     not equal to
  • >      greater than
  • <      less than
  • >=    greater than or equal to
  • <=    less than or equal to
  • or     this OR that
  • and    must be this AND that
  • contains    contains
Tags
  • Create the logic and control flow for templates
  • Denoted by curly braces and percent signs: {% and %}
Filters
  • Change the output of a Liquid object
  • Used within an output and are separated by a |


Examples of liquid basic syntax

CodeResult
{{ contact.firstname }}George


Fallback values; i.e. defaults

CodeResult
Hi {{ contact.firstname | default: 'there' }}Hi George

If Contact does not have a first name: Hi there


Control flow tags - based on number of employees

CodeResult
{% if contact.numberofemployees > 50 %}With a large organization like yours, communication is key.
{% elsif contact.numberofemployees > 5 %}In SMBs, the key is balance.
{% else %}In a micro-org like yours, you need to save every dollar.
{% endif %}


Control flow tags - based on email domain

CodeResult
{% if contact.email1.address contains ‘@gmail.com’ %}<a href= "https://help.keap.com/help/gmail-sync">Gmail sync for Keap</a> captures the email communications in Gmail into your contact record.
{% else %}<a href= "https://help.keap.com/help/gmail-sync">Gmail sync</a> and <a href= "https://help.keap.com/help/microsoft-sync">Microsoft email sync</a> for Keap captures email communications into your contact records.
{% endif %}


Dates

CodeResult
{{ today.date }}2019-08-13
{{ today.date | short }}8/13/19
{{ today.date | medium }}Aug 13, 2019
{{ today.date | long }}August 13, 2019
{{ today.date | full }}Tuesday, August 13, 2019
{{ today.date | plus_days: 14 | full }}Tuesday, August 27, 2019


Case statements

Hello ~Contact.FirstName~,

~Date.DayOfWeek~

{% capture day %}{{ 'now' | date: '%A' }}{% endcapture %}

{% case day %}

{% when 'Sunday' %} Check out our Sunday specials!

{% when 'Monday' %} Check out our Monday specials!

{% when 'Tuesday' %} Check out our Tuesday specials!

{% when 'Wednesday' %} Check out our Wednesday specials!

{% when 'Thursday' %} Check out our Thursday specials!

{% when 'Friday' %} Check out our Friday specials!

{% when 'Saturday' %} Check out our Saturday specials!

{% endcase %}

Use Liquid code in your app

You can create dynamic content anywhere merge fields are used in the app. For example, the case statements code above could be included in a broadcast like this:

And your clients would receive an email like this: