This training material will cover the following topics:
Liquid is an open-source template language created by Shopify and written in ruby. It is used to allow for more dynamic content on themes, pages, etc.
In Zendesk, we utilize liquid most commonly in triggers, automations, and extensions. We utilize this to allow for more dynamic messaging (comments, URLs, etc.). It can take time to learn how to fully utilize the liquid language, especially as there is a lot to it and it gets added to frequently.
To insert a value into a text/output, you would use double curly bracks around the name of the variable/function/value.
As an example, to output a ticket requester's name, you might do something like
Greetings {{ticket.requester.name}}
.
You can also use functions in this manner. As an example, if you wanted to put
your role into a message, but ensure it was capitalized, you might do something
like My role is {{current_user.role | capitalize }}
.
To use code blocks (common for loops, assignment, conditionals, etc.), you would
start the line with {%
and end it with %}
As an example, if you wanted to start a loop on ticket comments, you might do
something like {% for comment in ticket.comments %}
.
Object Type | Variable | Description |
---|---|---|
Current User | current_user |
A user object referring to the current user |
User | name |
The user's full name |
User | first_name |
The user's first name |
User | last_name |
The user's last name |
User | email |
The user's email address |
User | details |
The user's details text box |
User | notes |
The user's notes text box |
User | id |
The user's Zendesk ID |
User | organization |
The user's organization object |
User | custom_fields.gitlab_user_id |
The user's GitLab user ID (a custom user field) |
User | custom_fields.gitlab_username |
The user's GitLab username (a custom user field) |
User | custom_fields.xxxxx |
The user's value for a user field named xxxxx |
Organization | id |
The organization's Zendesk ID |
Organization | name |
The organization's name |
Organization | details |
The organization's details text box |
Organization | notes |
The organization's notes text box |
Organization | custom_fields.saleforce_id |
The Salesforce ID for an organization |
Organization | custom_fields.arr |
The ARR for an organization |
Organization | custom_fields.technical_account_manager |
The CSM for an organization |
Organization | custom_fields.account_owner |
The AM for an organization |
Organization | custom_fields.org_region.title |
The organization's region |
Organization | custom_fields.support_level.title |
The organization's support level |
Organization | custom_fields.xxxxx |
The organization's value for a organization field named xxxxx |
Agent | name |
The agent's name |
Agent | role |
The agent's role |
Agent | email |
The agent's email |
Agent | signature |
The agent's signature |
Ticket | assignee |
The ticket's assignee (a user object) |
Ticket | ccs |
An array of users who are CC'd on the ticket |
Ticket | due_date |
The ticket's due date (date only) |
Ticket | due_date_with_timestamp |
The ticket's due date (with timestamp) |
Ticket | id |
The ticket's Zendesk ID |
Ticket | in_business_hours |
A boolean if the ticket is currently in it's schedules hours |
Ticket | link |
The ticket's URL with the HTTP protocol |
Ticket | requester |
The requester of a ticket (user object) |
Ticket | organization |
The organization of a ticket (organization object) |
Ticket | status |
The ticket's status |
Ticket | ticket_field_xxxxxx |
The ticket's API value for ticket field with ID of xxxxxx |
Ticket | ticket_field_option_title_xxxxxx |
The ticket's dropdown title value for ticket field with ID of xxxxxx |
Ticket | ticket_field_360019949920 |
The ticket's unauthorized user field value (Zendesk Global) |
Ticket | ticket_field_360017383799 |
The ticket's due date notes (Zendesk Global) |
Ticket | ticket_field_360012194220 |
The ticket's partner troubleshooting value (Zendesk Global) |
Ticket | ticket_field_360020735339 |
The ticket's request for CCs value (Zendesk Global) |
Ticket | ticket_field_360012194200 |
The ticket's Organization email (partners) value (Zendesk Global) |
Ticket | ticket_field_360018253094 |
The ticket's preferred region for support value (Zendesk Global) |
Ticket | ticket_form |
The ticket's form |
Ticket | url |
The ticket's URL without the HTTP protocol |
Ticket | title |
The ticket's subject |
Ticket | comments |
An array of the ticket's comments |
Ticket | public_comments |
An array of the ticket's public comments |
Satisfaction | current_rating |
The current satisfaction rating of a ticket |
Satisfaction | rating_section |
The formatted block sent to user's request a satisfaction survey |
Satisfaction | current_comment |
The current satisfaction comment of a ticket |
There are many more that can be used, these are by far just the most common used at GitLab.
Function | Description |
---|---|
slice | Returns a substring |
split | Divides a string into an array based on a separator |
url_encode | Converts a string into URL encoded characters |
url_decode | Decodes a strubg tgat was encoded by url_encode |
first | The first item in an array |
last | The last item in an array |
join | Combines items in an array |
capitalize | Sets the first character in the string to uppercase |
upcase | Sets all characters in the string to uppercase |
downcase | Sets all characters in the string to lowercase |
size | Returns the size of the object. If a string, it is number of characters; if an array, the number of items |
lstrip | Removes whitespace from the left of a string |
rstrip | Removes whitespace from the right of a string |
strip | Removes whitespace from both the left and right of a string |
remove | Removes items in a string |
replace | Replaces items in a string |
sort | Sorts items in an array alphabetically |
truncate | Shortens a string |
uniq | Removes duplicates items from an array |
Tag | Description |
---|---|
assign | Assigns a value to a variable |
blank | The same as saying "nil" or "null" |
capture | Captures text into a variable |
break | Exit a loop |
continue | Skip the remaining code in a loop and start the next iteration |
Conditional | Operators available |
---|---|
if..elsif..else..endif | == != <> < <= > >= contains and or |
unless..endless | == != <> < <= > >= contains and or |
case..when..else..endcase | N/A |
Loop | Syntax |
---|---|
for | for x in y , for x in y limit:5 , for x in y offset:3 , for x in y reversed |
cycle | cycle "apple", "banana", "cherry" |
We use this in a trigger to determine the author, title, and description of the most recent comment to create a documentation issue.
{% for comment in ticket.comments limit:1 offset:0 %}
{% assign author = comment.author.custom_fields.gitlab_user_id %}
{% assign lines = comment | url_encode | split: "%0A" %}
{% for line in lines %}
{% assign first_five = line | slice: 0,5 %}
{% if first_five == 'Title' %}
{% assign title = line | url_decode | split: ': ' | last %}
{% endif %}
{% endfor %}
{% assign description = comment | split: 'Description:' | last | join: '\n' %}
{% endfor %}
Line by line breakdown:
for
loop on the ticket comments, setting a limit of 1 iteration
(meaning only grab the most recent one)author
lines
comment
into the function url_encode, to encode the
string into a URL safe format%0A
for
loop on the array stored in the lines
variablefirst_five
line
into the slice function, return the first 5 charactersif
block, with the condition being the value of first_five
is
Title
title
line
into the function url_decode, to undo what
url_encode previously did:
if
blockfor
loopdescription
comment
into the split function, which turns it into an
array split by the separator 'Description:'\n
for
loopWe use this to determine is a block of text should display based on if the ticket is currently within business hours or not.
{% if ticket.in_business_hours == 'false' %}
<li>You indicated in this ticket, #{{ticket.id}}, a "Preferred Region for Support." The current time is outside of that region's standard business hours. You can rest assured that this ticket will be addressed by the next available engineer in the selected region. It is important that you understand when you may expect a reply regarding this case. Please see the linked handbook section for more information regarding the <a href='https://about.gitlab.com/support/#effect-on-support-hours-if-a-preferred-region-for-support-is-chosen' target='_blank'>effect of using Preferred Region</a>.<br />During the course of this ticket if you require assistance outside of the selected region's standard business hours please feel free to reply asking one of our support engineers to set this ticket's preferred region to "All regions".</li>
{% endif %}
Line by line breakdown:
if
block, with the condition being if the ticket is not within
business hours{{ticket.id}}
if
blockWe use this as part of the triggers that create issues based on SSAT ratings customers leave us. This is used to determine the form the ticket is using and set a variable to be used containing the GitLab issue tag that corresponds to the ticket form.
{% assign form = ticket.ticket_form %}
{% if form == 'Gitlab.com (SaaS) User Accounts and Login Issues' %}
{% assign form = 'form::GitLab.com' %}
{% elsif form == 'Support for GitLab.com (SaaS)' %}
{% assign form = 'form::GitLab.com' %}
{% elsif form == 'Support for a self-managed GitLab instance' %}
{% assign form = 'form::Self-managed' %}
{% elsif form == 'Licensing and Renewals Problems' %}
{% assign form = 'form::Upgrades & Renewals' %}
{% elsif form == 'Contact the Security team' %}
{% assign form = 'form::Security' %}
{% elsif form == 'Other Request' %}
{% assign form = 'form::Other' %}
{% else %}
{% assign form = 'form::GitLab Community Edition' %}
{% endif %}
Line by line breakdown:
form
if
block, with the condition being if the value of form
is
Gitlab.com (SaaS) User Accounts and Login Issues
form
elsif
block, with the condition being if the value of form
is
Support for GitLab.com (SaaS)
form
elsif
block, with the condition being if the value of form
is
Support for a self-managed GitLab instance
form
elsif
block, with the condition being if the value of form
is
Licensing and Renewals Problems
form
elsif
block, with the condition being if the value of form
is
Contact the Security team
form
elsif
block, with the condition being if the value of form
is
Other Request
form
else
blockform
if
block