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:
- Using Liquid markup to support multiple languages in automations, macros, and triggers
- Modifying a ticket trigger to return a response based on business hours
- Using Liquid markup to customize the formatting and placement of text in comments and email notifications
- How can I format placeholders with liquid markup?
60 comments
Support Department
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?
0
Austin Killey
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!
0
Support Department
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)?
0
Allen Lai | Head of CX at Otter.ai
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:
0
Dean Kongslie
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.
2
Austin Killey
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!
0
Dean Kongslie
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?
0
Austin Killey
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.
0
Dean Kongslie
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.
0
William Grote
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
0
Dean Kongslie
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
0
Riah Lao
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
0
Dean Kongslie
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:
0
Rafael Santos
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
0
John DiGregorio
We had a trigger in place to translate language and it all of a sudden stopped working translating to French for French users. We tried creating this in a Marco and still the end user received the body of the email in English but the subject of the email in French. Any help would be greatly appreciated.
% case ticket.requester.language %}
{% when 'French'%}
Cher(e) {{ticket.requester.name}},
Vous nous avez sollicités pour vous aider sur le sujet suivant "{{ticket.title}}" #{{ticket.id}} :
Nous vous remercions pour cette suggestion. Nous transmettons le sujet à notre équipe Produit et fermons le ticket. Pour le suivi et avoir plus d'informations sur ce sujet, n'hésitez pas à vous adresser à votre CSM.
Cordialement,
Votre équipe support
{% else %}
Dear {{ticket.requester.name}},
You have asked us to help you on the following subject "{{ticket.title}}" #{{ticket.id}}:
Thank you for this suggestion. We will forward the issue to our Product Team and close the ticket. For follow-up and more information on this topic, please contact your CSM.
Sincerely,
Your support team
{% endcase %}
0
Jacob the Moderator
Hey John,
Looks like you are missing the the opening curly bracket {
In
% case ticket.requester.language %}
It should be:
{% case ticket.requester.language %}
👆 See if that helps.
0
John DiGregorio
Jacob the Moderator - I missed it in the cut and past into this thread - we have tested the triggers and Macros and nothing seems to work.
0
John DiGregorio
Jacob the Moderator
I was curious to know as it is being passed as a ticket field "Requester.Language" if it would show up on a report and it doesn't. What does show up on a report is Requester.Locale - if you change the code to the New Code below it works like a champ - just tested. Not sure why it doesn't work with Language - it worked fine when we set it up a year ago
{% case ticket.requester.language %}
{% when 'French' %}
{% case ticket.requester.locale %}
{% when 'fr' %}
0
Jacob the Moderator
That's a great solution!
I still don't know why the language wouldn't work, I've used it on the past. But locale should work just fine.
0
John DiGregorio
Jacob the Moderator - we have a ticket into support - I am wondering if they deprecated language as it isn't on the ticket reports like Locale
0
Jacob the Moderator
Please let me know what they find.
I don't believe it has been deprecated, more likely I think it has to do with the language that the string denoting the language - I recall having a similar issue years back.
In this article both English and Italian is used to specify language, which is confusing:
https://support.zendesk.com/hc/en-us/articles/4408842967578-Using-Liquid-markup-to-support-multiple-languages-in-automations-macros-and-triggers
0
Rafael Santos
Jacob the Moderator and John DiGregorio Language still works as expected, though not as described above.
In your example:
The language is translated to the receiving user's profile language settings.
Therefore it would render as "French" for an English user, but "Français" for a French user. (Example: sending a notification to an English agent and French customer)
Locale is as you've described the safe approach when customizing these.
0
Adam
Austin Killey I'm currently trying to use the Liquid Markup with a checkbox on an organization custom field. But regardless if the checkbox is checked or not it always defaults to "No".
I'm not sure why this is happening. Which I pulled information on this snippet from https://support.zendesk.com/hc/en-us/articles/4408887218330-Using-placeholders#topic_nfn_yxq_j2b
0
Dave Dyson
Adjusting your Liquid to this should work:
0
Adam
Hey @...
I've made the change you've suggested, but unfortunately we are still seeing the same result, it's always defaulting to no. So when the checkbox is selected it does not satisfy the first if statement.
Working with Zendesk support I've also tried this with similar results.
0
Dave Dyson
0
Rafael Santos
Hey Adam and @..., I've played around with those and found its solution (proof below). The following will work for your example:
To test these, I've created 2 Org checkbox fields:
Setting my Test ticket's Org's "True Boolean" to Checked, and leaving "False Boolean" as Unchecked.
I've used the following in a test macro:
Which returns this Macro Preview on the aforementioned test ticket, confirming that these work as expected:
1
Dave Dyson
0
Adam
I can confirm this worked perfectly. Thank you both for helping on on this one.
0
Dave Dyson
The only brand placeholder that should work is ticket.brand.name; there are no placeholders for the brand id -- see Zendesk Support placeholders reference.
0