If you're familiar with placeholders in Zendesk Support, then you already know something about Liquid markup. It's the templating language we use to enable them. Placeholders are used in automations, macros, targets, triggers, and widgets as containers for dynamically generated ticket and user data. What you may not know about Liquid markup is that you can also use it to customize how this data is selected and displayed as output. This is because Liquid also allows you to create simple programming logic such as case statements, if statements, for loops, and so on.
By writing simple control statements directly in the comment/description action in macros and the email user action in automations and triggers, you can accomplish in one automation, macro, or trigger what you used to have to do in multiple automations, macros, and triggers. You can also customize how comment text is presented.
You can find the Liquid documentation at Liquid for Designers. All of the elements of the language are described in detail. Here, however, is a brief introduction to how it works.
Liquid is a templating language for rendering email and HTML. Liquid is the mechanism that enables the automated placement of data in comments and email notifications using placeholders.
- Output, which is text output contained in double curly brackets.
- Tags, which contain the programming logic that determines how the data is expressed with placeholders.
If you simply equate output with placeholder, you're about half way to understanding what Liquid is and how it's used. What you may not know about Liquid output however is that in addition to expressing ticket and user data, there are also methods available to manipulate text strings and arrays. In Liquid, these methods are referred to as filters. Using a filter you can transform text to uppercase characters, for example. But that's one of the simplest examples of what filters can be used for. See the Liquid documentation for more information.
The other half of understanding of how Liquid can be used comes from knowing what tags are and how they are used. Tags provide the programming logic that you can use to select and present data.
Using Liquid tags you can create:
- if else statements
- case statements
- for loops
- cycles
- variable assignments
For more examples of how Liquid markup can be used, see the following articles:
14 Comments
I have added links to KB articles in automated replies to customers. But I never know if the requester clicked the link.
Is there any way or trick with liquid to find out whether this link has been clicked (viewed) by the customer?
Hey there @...,
Really great question about using Liquid to track article link views. Sadly, Liquid markup tends to work best mostly as a visual language that'll change text appearance based on certain conditions, so we may be out of options for tracking link activity that way, but:
For tracking link views, using something like Answer Bot would be perfect, as articles suggested by Answer Bot are able to have their activity tracked, including link views. When Answer Bot suggests articles to the ticket requester, ticket events will be generated to let you and your agents know that the requester has actually viewed those articles, where the requester may have also marked if those articles were helpful or not:
Otherwise if you'd prefer to track only specific article links that you've embedded in your automatic replies rather than go off of suggested Answer Bot articles, enabling and integrating Google Analytics looks to be pretty promising, where you could possibly add some event listeners in your help center to track a visitor's "referrer URL" and get a better picture of where your KB article views are being redirected/referred from.
Hope this helps!
Hi Austin,
Thank you for the answer. In our case we have some specific article links embedded and which show up when typical keywords are in the request (used liquid for that).
Haven't tried Google Analytics yet, but will do so. Is this the only option?
Would there also be a HTML option (e.g. an embedded button which 'fires' some actions when clicked by the requester)?
Sometimes we may solve a ticket without assigning it to an actual agent. In that case, we don't want to insert a blank name in our c-sat trigger. If I understand liquid, I would insert this into the email body within the automation:
Hey Team!
We have a trigger that we are using to set the subject of a ticket. I have 3 custom fields that we evaluate and depending on null / not null values in each field we have a slightly different subject.
Can anyone evaluate my Liquid code as it does not actually update the subject even though the trigger is firing.
Hey there Dean Kongslie!
Super solid chunk of Liquid there - thanks so much for sharing. The syntax & formatting seems solid so far from what I can see..
With the trigger firing, do you happen to see any target failures showing up for your ticket-focused target in your Target Failures tab here?
Triggers can still run and notify their targets, but you and I will just need to make sure these subject payloads are being accepted by our API. If you don't see any failures for your target or if you do but aren't sure what the target failures mean, let me know and I can spin up a ticket to work on this more closely together.
Thanks again Dean - let us know if you need anything else!
Austin Killey I was actually able to figure this one out a moment ago. I realized that it was because I had page breaks to make for clean code. I needed to have the entire subject code on a single line so the JSON would push correctly.
I do have another question though. On a related trigger I have I am hitting the same webhook which is a PUT to the endpoint /api/v2/tickets/{{ticket.id}}.json and sending some liquid code through. The custom field is a checkbox and I want to evaluate if it is true or false. The issue is when I input {% if ticket.ticket_field_4412877472404 %} it always evaluates to true. Is there something with checkboxes I need to know about?
Dean Kongslie - that's awesome! Good catch on the line breaks throwing off the Liquid output.
Really good question as well: With that IF condition, we'd be evaluating whether or not there's any value present for your checkbox field. With checkboxes that are active and applied to a ticket, they can only be true or false (1 or 0), so with either of those values present at all times, your IF statement will always return true.
With that in mind, feel free to copy this if/else condition below and use as you see fit! Quick heads up that this snippet also has line breaks to make it look nice and neat, so when you're ready to use this in your payload, you can combine this all into a single line just like your ticket subject markup.
Austin Killey thank you very much. I had tried something similar, but I didn't realize I needed to do contains 1 or 0 since the JSON reads true or false.
I appreciate your help.
Dean Kongslie
I'm trying to figure out a way to have a trigger change the subject line of a ticket right after it has been submitted so that is updates to a standard format with the selected values from 3 different custom fields, can you share the trigger you references in your post - I can't see how to use a trigger to set the subject line
William Grote
As part of your trigger actions you need to include "Notify Active Webhook". Then select the webhook you want to use (more on this later) and paste the JSON that will be sent through the webhook to update your ticket subject. Here is an example:
Replace the 1, 2 & 3 at the end of the ticket.ticket_field with the appropriate field id.
Here is a link to create webhooks. You will want to create a ticket PUT webhook for this feature: https://support.zendesk.com/hc/en-us/articles/4408839108378-Creating-webhooks-in-Admin-Center
Hi,
1. Is there a way to "escape" or what to replace single quote ' within the if else condition?
For example:
{% if ticket.brand.name == 'XYZ's' %}
2. Does "else if" work?
Thanks,
Riah
Riah Lao I am not positive as I haven't had to do this in Liquid yet, but in SQL for example you would add a 2nd quote. So your if statement would look like this:
Riah Lao yes, you can use double quotes there, and Else If works too.
You'll find more info on the Liquid documentation > Control flow
Please sign in to leave a comment.