Forums/Documentation/Extending your Zendesk

Using Liquid markup to customize comments and email notifications

Anton de Young
posted this on May 20, 2011 07:38

If you're familiar with placeholders in Zendesk, 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.

A brief introduction to Liquid markup

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. In Zendesk, Liquid is the mechanism that enables the automated placement of data in comments and email notifications using placeholders.

There are two types of markup in Liquid:
  • 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 in Zendesk. 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 in Zendesk 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

As an example, based on ticket properties you can create different responses in your business rules. This example shows how you can modify the Notify requester of received request trigger (or any other trigger that serves the same purpose) to return a response based on your business hours.

{% if ticket.in_business_hours == 'true' %}

Hello {{ticket.requester.first_name}}

Your request (#{{ticket.id}}) has been received and is being reviewed by our support staff. 

To review the status of the request and add additional comments, follow the link below:
http://{{ticket.url}}

{{ticket.comments_formatted}}

{% else %}

Hello {{ticket.requester.first_name}}

Your request (#{{ticket.id}}) has been received and will be reviewed by our support staff during regular business hours (Monday - Friday, 8am - 6pm PST). 

To review the status of the request and add additional comments, follow the link below:
http://{{ticket.url}}

{{ticket.comments_formatted}}

{% endif %}

Using a simple if...else statement, the first response is sent if the request is received during business hours and the other is sent if it is not. The if statement tests theticket.in_business_hoursproperty and responds accordingly. The ticket property is in the same format that you're familiar with when it's used as a placeholder, although not contained within double curly brackets for the simple reason that it's not being used as output here but rather as part of the logic determining what will be included in the comment when it's sent to the requester as an email notification.

For several other examples of how these simple statements can be used in Zendesk, see Using Liquid markup to support multiple languages in automations, macros, and triggers and Customizing the formatting and placement of text in comments and email notifications below.

These are just several examples of what you can do with these simple but powerful Liquid tags.

Using Liquid markup in Zendesk

Here are several more examples of how Liquid markup is commonly used in business rules to customize comments and email notifications.

For the complete list of Zendesk data objects that can be used in your Liquid code, see Zendesk data object (placeholders) reference.

Note: You may find it convenient to test your Liquid markup in a test macro since you can see the results immediately by applying the macro to a ticket.

Using Liquid markup to support multiple languages in automations, macros, and triggers

Many companies and organizations support end-users who speak languages other than English and there are a number of ways to manage this in Zendesk. In this example, a case statement is used to determine what response is sent to the end-user based on their language setting. The email body of the Notify requester of received request trigger contains the following Liquid markup:

{% case ticket.requester.language %} {% when 'Italiano' %}

Ciao {{ticket.requester.first_name}}

La tua richiesta (#{{ticket.id}}) è stata ricevuta, è stato esaminato dal nostro staff di assistenza.

Per esaminare lo stato della richiesta e aggiungere ulteriori commenti, segui il link qui sotto:
http://{{ticket.url}}

{{ticket.comments_formatted}}

{% when 'Danish' %}

Hej {{ticket.requester.first_name}}

Din anmodning (# {{ticket.id}}) er blevet modtaget og bliver gennemgået af vores supportmedarbejdere.

At gennemgå status for anmodningen og tilføje yderligere kommentarer, skal du følge nedenstående link:
http:// {{ticket.url}}

{{ticket.comments_formatted}}

{% else %} 

Hello {{ticket.requester.first_name}}

Your request (#{{ticket.id}}) has been received, and is being reviewed by our support staff. 

To review the status of the request and add additional comments, follow the link below:
http://{{ticket.url}}

{{ticket.comments_formatted}}

{% endcase %}

The language preference is set in the user's profile. Language support is defined by an administrator (on the Localization tab of the Account page) and you use the names (the exact text string) as displayed in the list of languages on that page.

Note: This example just shows the notify trigger. You'd also want to do the same thing for the update and solved triggers and any other business rules that generate comments and email notifications to the end-user.

In this example, we could have also explicitly declared the English text like the others ({% when 'English' %}). However, if the default language is English it's not necessary. The English text will be displayed to all users who have not otherwise chosen a language setting.

As you can imagine, you can use something like this for any number of reasons, not just to support multiple languages. For example, maybe you want custom responses for users in different organizations for some reason. If so, you useticket.organization.namein a case statement like this.

Customizing the formatting and placement of text in comments and email notifications

By default, many of the Zendesk business rules use the {{ticket.comments_formatted}} placeholder to include comments into email notifications. If you want more control over how the comments are presented to requesters, you can access more details about comments and their attachments using Liquid markup.

A comment is an element within a ticket and there are a number of placeholders available that you can use to include comments in email notifications. For example, you can include all comments, public comments, the last comment, etc (see Comment data).

If you want more control over how comments are displayed in email notifications, you can use Liquid markup and a for loop, as in this example:

{% for comment in ticket.comments %}

   Comment:
   {{comment.created_at}}
   {{comment.author.name}}
   {{comment.value}}

   Attachment:
   {% for attachment in comment.attachments %}
   {{attachment.filename}}
   {{attachment.url}} 

   {% endfor %}

{% endfor %}

This returns the items in both arrays (ticket.comments and comment. attachments). In other words, the properties for every comment and attachment contained in the ticket.

If you want to only return the last comment, you can use the limit and offset attributes as in the following example:
{% for comment in ticket.comments limit:1 offset:0 %}
You can do a lot with arrays in for loops. Refer to the Liquid documentation (Liquid for Designers) for more details.
 

Comments

User photo
Claire
truecontext

what date format is required for ticket.due_date

June 03, 2011 09:39
User photo
Anton de Young
Zendesk

Claire,

When you set the ticket type as task, you can select a due date from the calendar control and it's displayed in the ticket in this format: June 10, 2011. But when you return that data it's in this format: Jun-10. Same as the other dates. Thanks for catching that. 

June 03, 2011 10:06
User photo
Claire
truecontext

Thanks, Anton … I’d like to do this on the email subject line of tasks I am inserting from another system … is it possible to do something like … {{assignee:JoeAgent ticket_type:task due_date:20111225}} ?

June 03, 2011 14:56
User photo
Anton de Young
Zendesk

Claire, 

Yes that works. You'll also want to include a description in the subject line or your ticket subject will be blank because, of course, the code is setting ticket properties. 

June 03, 2011 16:40
User photo
Claire
truecontext
When I use the above format, the ticket comes in with today's date rather than the date I specified. I assumed it was the date format I used.
June 03, 2011 17:00
User photo
Quinton McCombs
Project C Beta Testers

Does this also work in the HTML email template as well?  For example, I would like to change the format for the template based some data in the ticket or some attribute or the user or organization...

June 06, 2011 21:37
User photo
Anton de Young
Zendesk

Claire, 

It turns out that due_date is not currently supported by the mail API (http://www.zendesk.com/api/mail-api).

June 07, 2011 06:36
User photo
Anton de Young
Zendesk

Quinton, 

No, that's not supported yet. See this: https://support.zendesk.com/entries/142681-allow-any-placeholder-in...

June 07, 2011 08:46
User photo
Rafal Kalicki
wordwatch

Hi

{{comment.created_at}} reutrn eg Jul-22, how can I achieve such a format Jul-22 09:37 (CEST)

Also, I noticed that formatted_comments placeholder by default displayes the most recent one, whereas the rest of the comments is hidden and available to watch via -show quoted text- - how can I achieve that?

 

 

July 22, 2011 01:38
User photo
Idunckel
How do you make the text the URL. When I used your suggestion, I got a long link and a filename... {% for attachment in comment.attachments %} {{attachment.filename}} {{attachment.url}} {% endfor %}
August 11, 2011 18:01
User photo
Björn Bauer
cmmarketing

Hi Anton!

Great feature. I'd like to display all CC's except they are agents (to prevent direct mailing to the light agent).

Can I do something like "If CC is a user, display CC" ?

Thanks for the help,
Björn 

November 04, 2011 04:05
User photo
Anton de Young
Zendesk

Björn, 

I assume you're referring to this tip of the week: http://www.zendesk.com/blog/showing-whos-been-ccd-in-email-notifica...

There's no way to do what you're asking using Liquid. Not that I can figure out anyway. But, an end-user ticket requester sees other end-users who have been CC'd by default (in the email header) not any agents who have also been CC'd. Is that what you're after? 

November 09, 2011 16:22
User photo
Alun Carp
abiquo

I too would like to know how to format dates in notification emails.

If I let Zendesk create the comments/descriptions it appears to formats with "%b-%d %H %M (%Z)"  eg. Nov-25 06:05 (CET). If I format the comments myself and use the created_at placeholder without formatting it will only display Nov-25, if I add the same formatting it displays as Nov-26 00:00 (UTC).

Having the time as well as the date is useful to have in emails, how do we get that?

For example, I have this liquid markup:

{{ticket.created_at | date: "%b %d %H %M %Z"}}

Yet the time and time-zone are always 00:00 UTC, probably because created_at is a string containing just the date.

The information is obviously available when Zendesk creates the comments in emails, please make it available to those of us who are trying to do this ourselves.

November 24, 2011 23:23
User photo
Alun Carp
abiquo

Zendesk, any comment of formatting dates please?

November 30, 2011 13:57
User photo
Skip Moore
Zendesk

@David, I looked into this and the liquid markup {{ticket.created_at}} only contains the Month and Day. This is why you are seeing 00:00 UTC when using %H %M %Z, because there is no data to convert. I have to talked with product and we are planning to create a new markup that will contain the full date, I'll update you when it's deployed .

December 06, 2011 14:34
User photo
Alun Carp
abiquo

@Skip, any news on that update to provide the full date?

January 18, 2012 21:44
User photo
Skip Moore
Zendesk

@Alun, I don't have a status update today . I will go bug the dev's 

January 19, 2012 08:01
User photo
Alun Carp
abiquo

@Skip, how did bugging the dev's go?

February 01, 2012 15:21
User photo
Skip Moore
Zendesk

@Alun it's on the schedule for next week for dev time.  So another week for QA in about 2 weeks. Sorry for the long wait but we haven't forgotten it 

February 01, 2012 15:33
User photo
Lorraine Joubert

I would like to strip html from e-mails entering Zendesk and thus automatically generating a ticket.  Currently, if an e-mail contains html, this ends up in the description of the Zendesk ticket in plain html and looks terrible to the user when communication is sent that needs to include the ticket description.  How can I strip this html at ticket creation?

February 17, 2012 03:01
User photo
Lorraine Joubert

Does anyone have any feedback on my last comment, please?

February 20, 2012 00:21
User photo
Skip Moore
Zendesk

@David @Alun you can now get the full time by adding _with_time to a time based placeholder for example {{ticket.created_at_with_time}}

March 07, 2012 11:09
User photo
Alun Carp
abiquo

@Skip, has this been promoted to production?

I have just tried the following markup and get a blank line for the 'with_time" placeholder.

 

{% for comment in ticket.comments limit:1 offset:0 %}
Comment:
{{comment.created_at}}
{{comment.created_at_with_time}}
{{comment.author.name}}
{{comment.value}}
{% endfor %}

March 07, 2012 20:01
User photo
Alun Carp
abiquo

Ok, it looks like this was only added to ticket.create_at as ticket.created_at_with_time does include the time.

Using the filter  date: "%b %d %H %M %Z" does now format the date and time but I still get UTC for the timezone whereas our portal is configured as CET. I can see from the text when no filter is used that this is because no timezone information is included in the _with_time variant.

Perhaps a _full variant needs to be implemented so that the full date filtering available in liquid markup can be used on any date (ticket, comments, description, etc.) available for notifications.


March 07, 2012 20:43
User photo
Rob Eyre
bookdepository

A couple of discoveries that might save some headaches:

  • Warning: if Zendesk can't compile your Liquid template in eg a dynamic content block, it will just send through the code
  • the 'elseif' tag is actually elsif:
    {% if a == 1 %}one{% elsif a == 2 %}two{% endif %}
April 18, 2012 04:57
User photo
Thomas Moreau

Hello, 

I'm trying to set widgets in the right language for our users, as we have a bilingual Zendesk (French and English).

Our customers have language preferences set in the web platform we've created. When they click on 'support', it generates a tag in Zendesk to that user, with the language preference ('fr' or 'en').

Using Liquid programming, I've built custom widgets like:

{% if tags == 'fr' %}
Visitez notre aide en ligne !
{% else %}
Online help available here!
{% endif %}

Those widgets are placed on different places, but mainly on the homepage, to welcome them in their own language.

Besides, I've set a trigger that says:

"If tags contain at least on of the following: fr, then requester's language is French".

All of this doesn't work:

  • my custom widgets are displaying only what is contained after the {% else%} tag, whatever tag the user has.
  • the language preference of a user with corresponding menu items 'check your existing requests' being 'vérifier vos demandes' in French doesn't change.
Please, can you help, as it's been a long time we're trying to set things properly and better satisfy our customers.

What should we do to have the language preference of our system automatically reflected in Zendesk?
May 24, 2012 07:25
User photo
Will Dobbins

@Skip, trying to customize my notifications to users based on their feedback and I'm unable to do so effectively because fundamental fields are simply not available...  The default formatted comments contain everything I need, however those same value's aren't exposed so I can't customize my formatting...

The specific issue is the with_time feature discussed above, it seems half-done to add with_time to one field and ignore another...

June 29, 2012 07:17
User photo
Skip Moore
Zendesk

@Will which issue? The same one Thomas is having?

June 29, 2012 07:54
User photo
Will Dobbins

Skip,

Formatted comments come out:

User, Jun 29 09:47 (CDT):

Comment

I am unable to replicate this with the available Liquid Markup as it doesn't appear that the date/time/timezone is exposed on the COMMENT object.

June 29, 2012 07:57
User photo
Eli Blankers
accelitec

Is there a way to add the 'Related  Topics' to an email through placeholders?

July 11, 2012 13:16
User photo
Jovana Milutinovich
This article has been translated into Serbo-Croatian language by Jovana Milutinovich from http://webhostinggeeks.com/. It can be viewed here: 
September 04, 2012 02:21
User photo
Jonathan March
Enthought

The Liquid For Designers page does not contain a list of operators. It would be helpful if you would provide such a list  (for example the "contains" operator is very useful but is not easily findable - there is an example using it on that page.) Thanks!

September 04, 2012 15:29
User photo
Henrik Nyh

You might also mention truncation: we use this in a HipChat notification:

{{ticket.description | truncate:400}}

September 30, 2012 11:37
User photo
Arnaud de Theux
Zendesk

Thanks @Henrik !

DIdn't know this feature and I am using the HipChat as a channel to shoot some information from my Zendesk, so this is perfect to avoid uninteresting long blah blah :-)

September 30, 2012 14:27
User photo
Jehanzeb Afridi
globaltel

Hi,

I want to customize the Subject of first email response when user submits a ticket. The subject contains brackets () surrounding the ticket number. I want to remove the brackets(). The subject look like:

Thank you for contacting XYZ Support (ticket #94262)

I want it to look similar to

Thank you for contacting XYZ Support. Your ticket is #278098

I have used liquid markup for this as

Thank you for contacting XYZ Support. You ticket is #{{ticket.id}}

But it gives the output like

Thank you for contacting XYZ Support. You ticket is #94262 (ticket #94262)

It always concatenation (ticket #94262) to the end.

How can I force Zendesk not to concatenate (ticket #94262) at the end.

October 01, 2012 01:37
User photo
Hagop Hagopian

Is there a way that I can edit their first comment or even delete it when I send them a note through their email, reply?

October 03, 2012 08:08
User photo
Ted Barnum
Zendesk

@Jehan
If you are using a Default ReplyTo address that is outside of your zendesk subdomain, then we place the ticket ID in the Subject line and in the syntax you specified, as one method of connecting replies back to tickets. This can be modified (but not entirely removed) if you specify in your Triggers that Outbound emails have a #{{ticket.id}} in the Subject line, in which case we should not put the other text- syntax of (ticket #94262) in emails to end users .
Note that Agent sees a security hash instead of the ticket ID.
If you are not seeing the above behavior, then please open a ticket so that we can look into the details.

October 15, 2012 11:56
User photo
Justin Graves
ensign

The link to "Liquid for Designers" is broken.  It goes to https://github.com/tobi/liquid/wiki/liquid-for-designers which is showing a 404 error.  Can you post an updated link and maybe update the 2 places it is listed in the original article?  Thanks.

October 16, 2012 14:05
User photo
Dennis Theisen
Shopify

Here is an updated link to the Liquid documentation:

https://github.com/shopify/liquid/wiki/liquid-for-designers

January 08, 2013 07:50
User photo
Jennifer Rowe
Zendesk

Thanks Justin and Dennis! I updated the links in the article.

January 08, 2013 10:41
User photo
Dennis Theisen
Shopify

I have the same issue Will Dobbins and Alun Carp were having.

Basically I need to print out the created_at hour and minute (and timezone) information for comments. Initially it was suggested to use comment.created_at_with_time.

But this additional field is not available on a comment it looks like, only on tickets (e.g. ticket.created_at_with_time).

We are currently customizing how the notification emails sent back to customers look and this is the last step preventing us from shipping this. Just having the date is not great for conversations that update quickly during on day.

It should be a fairly straighforward fix for the developers to make this available for comments if it's already available for ticket timestamps.

Thanks!

March 25, 2013 14:17
User photo
SoCal Engineer

For those of you that are having trouble with the date for the created_at field the answer is that the create_at field is a standard date in LiquidMarkup so you can use standard LiquidMarkup to format the date as you wish. Here is a reference guide:

https://github.com/Shopify/liquid/wiki/Liquid-for-Designers

Here is an example that I used in my configuration:

{{ comment.created_at | date: "%b %d %I:%M (%Z)" }}

 

That returned a date format that looks like this:

Apr 02 12:00 (UTC)

Additional customization is up to you based on the above guides. Hope that helps!

April 02, 2013 14:00
User photo
Dennis Theisen
Shopify

That's exactly what I attempted and tried to explain in my last comment. Unless I'm doing something really stupid this does not work, try it yourself with a comment creation and see if you can get it to show another time than midnight.

The time information is not provided in that field which is why the Liquid date filter can not extract the hour, minute and timezone information.

A someone else suggested created_at for comments is probably just exported as a string of the date internally which Liquid will convert to a date for you, but there is no hour/minute/timezone information.

April 02, 2013 14:13
User photo
SoCal Engineer

Wow you're right Dennis, it only shows up as 12:00. I have submitted a ticket to ZenDesk, hopefully they will fix this bug.

April 02, 2013 14:41
User photo
SoCal Engineer

They have updated the ticket to L2 support.. I hope they implement it soon! All they have to do is populate those fields with the date and time arghhh...

April 03, 2013 12:22
User photo
Bagpuss in London

This remains a problem for us in that comments all show as having been entered at 12:00 UTC.

We've backed out of the customised route until Zendesk address this issue, because we can't send notifications showing not just the wrong time but the same time on each one.

In addition because a timestamp is the most obvious way to establish sequence in busy tickets, such an omission means Liquid markup is of little value to anyone wanting to create new notifications.

Others have asked similar questions in other entries some while back, e.g.

Zendesk data object (placeholders) reference
https://support.zendesk.com/entries/20203943

Come on chaps, update please! This one can't be hard.

April 08, 2013 00:37
User photo
James Dietrich
Zendesk

@Will Dobbins, @Bagpuss in London, @SoCal Engineer, @Dennis Theisen

I'm happy to say that the {{ comment.created_at_with_time }} placeholder is now available in Zendesk. So, for instance, if you call {{ ticket.latest_comment.created_at_with_time }} the resulting date object contains the timestamp of the most recent comment, presented in the timezone of your account (editable under Settings > Account > Localization). One caveat is that timezone information is not stored in this object, so the timezone value (i.e. %Z) always shows up as "UTC", even though the timestamp itself is presented in your account's local time. If your account is set to PDT, you could present the time object this way: {{ ticket.latest_comment.created_at_with_time | date: "%Y-%m-%dT%H:%M:%S-08:00" }}.

May 03, 2013 07:39
User photo
Alex Wolfe

Is there a way to disable liquid markup in tickets?  We support products that also use liquid markup.  So when a customer opens a ticket that contains liquid markup, all the variable placeholders are removed.  I can't think of a case where we'd actually want to use liquid markup in a ticket.

May 03, 2013 09:34
User photo
Dennis Theisen
Shopify

@Alex Wolfe:

Emails that customers write with Liquid content should show up properly (I just tested this and worked for me).

For replies from your agents you're right the Liquid will get evaluated and not show up properly for the customer.

Liquid supports a "raw" tag that prevents that evaluation, e.g.:

 

The following content inserted by and agent will get evaluated and not show up properly: 

{% if true %}
it's true: {{ true }}
{% else %}
it's false: {{ false }}
{% endif %}

 

But this content inserted by and agent will not get evaluated and should show up properly: 

{% raw %}
{% if true %}
it's true: {{ true }}
{% else %}
it's false: {{ false }}
{% endif %}
{% endraw %}

May 03, 2013 09:52
User photo
Dennis Theisen
Shopify

@James

thanks a lot for that, this works as expected.

I used "EDT" instead of "-04:00" at the end, but the only little annoying issue seems to be that after a few month this needs to be changed to EST (-05:00) instead. Is there any way to insert your account's timezone maybe?

May 03, 2013 12:55
User photo
James Dietrich
Zendesk

@Dennis 

I agree that it would be preferable to populate a timezone value automatically. Unfortunately I don't know of a way to present timezone data using a placeholder (even the REST API doesn't appear to expose that data). You could write a script that would use the REST API to update any content containing the placeholder when the offset changes, but that may be more trouble than it's worth. I'm sorry there isn't a better way to do this.

May 07, 2013 08:12
User photo
Scott San Filippo

Do we have access to the comment type (private or public) for markup and display? This would be essential for using the comments loop above. 

May 10, 2013 15:20
User photo
Brandon K.
Zendesk

Hello Scott,

Yes, markup will display for both public and private comments.

May 13, 2013 10:50
User photo
Tal Admon
qualisystemscom

Is there a way to get if a comment is public or private?

something like: comment.ispublic that will return true or false ?

May 31, 2013 17:27
User photo
Joel Sapp

Hi,

In this article, it was stated that: liquid markup could:

Using Liquid tags you can create:

  • if else statements
  • case statements
  • for loops
  • cycles
  • variable assignments

I am most interested in variable assignments. Can you give an example of how I could assign to one of the markup variables. Maybe a ticket tag ?

We'd really like to set a tag based upon the time of day that a ticket comes in. Seems like this should be possible but I have yet to see one assignment used in placeholders for ZD. 

 

July 01, 2013 18:03
User photo
James Dietrich
Zendesk

Hi Joel,

Unfortunately, the phrase "Using Liquid tags" is a bit misleading in this context. It's not implying that you can create or edit tags on a Zendesk ticket using Liquid Markup, but is merely a reference to the markup itself (in the sense of "HTML tags"). In other words, it is saying "Using Liquid Markup you can create: ..."

To actually add tags to the ticket, you'd have to use workflow rules, the REST API, or a manual process. However, if you are still interested in doing variable assignment, I've included an example below using "capture":

{% capture tags %}
{{ ticket.tags }}
{% endcapture %}

{{ tags | split: " " | last }}

The above snippet will allow you to assign the data in the ticket.tags to a variable called "tags" (in this case, it's really just for convenience because you can run the original ticket.tags object through the "split" filter as well).

August 07, 2013 13:52
User photo
Joe Edwards

I'm having a bit of difficulty with the split filter.  Is that supported in ZenDesk's current implementation of Liquid?

Here's an example of the issue I've encountered.  I've copied this example from Liquid's documentation on the "Split" command (with slight modification):

{% assign words = "Uses cheat codes, calls the game boring." | split: ' ' %}
First word: {{ words.first }}
First word: {{ words[0] }}
Second word: {{ words[1] }}
Last word: {{ words.last }}
All words: {{ words | join: ', ' }}
  {% for word in words %}
- {{ word }}
  {% endfor %}

 

The output I receive is:

First word: U
First word:
Second word:
Last word: .
All words: Uses cheat codes, calls the game boring.

 

It doesn't look like the split actually occurred.

Is there a different way I could perform a split?

August 22, 2013 17:47
User photo
James Dietrich
Zendesk

Hi Joe,

Zendesk does support the split filter. For instance, the following markup

{{ "Uses cheat codes, calls the game boring." | split: ' ' | first }}

results in the output below:

Uses

I think the issue in your example may have to do with the fact that you're trying to invoke the split filter in a Tags block. According to the Liquid docs here, filters can be used in Output blocks but (evidently) not in Tags blocks. Additionally, I'm not sure it's possible to assign a collection to a Liquid variable as in your example.

That said, I think most of the functionality you're looking for is still available even in Output blocks. For instance, you can still split and join. The following markup

{% assign words =  "Uses cheat codes, calls the game boring." %}
{{ words | split: ' ' | join: ',' }}

results in the output below:

Uses,cheat,codes,,calls,the,game,boring.

Let us know if you have any more questions.

September 16, 2013 09:55
User photo
Tobias Braun
global

Hello,

i want to highlight employee's in the email. Is there any way to achive this?

October 09, 2013 06:10
User photo
Stéphane Leduc

Hello, I was wondering where I can found the language slug to enter for  "Français (Canada)" in the liquid markup. 

Example: {% case ticket.requester.language %} {% when 'French' %}

October 10, 2013 08:11
User photo
James Dietrich
Zendesk

@Stephane, it should just be "Français (Canada)". I just tested this out by creating a user, setting his language to Français (Canada) and using the {{ ticket.requester.language }} placeholder in a private comment on his ticket. Are you running into trouble using the string "Français (Canada)" in your case statement?

@Tobias, could you elaborate on your use case? What do you mean by highlight employees?

October 10, 2013 10:52
User photo
Andrew

Is the full liquid functionality available in SideBar apps?   I've written a custom app that I'd like to use a filter (probably the escape filter), but I can't get any filters to work.

So this works:

<blockquote>

> <p>2.0 Email Search:
> <a href="https://our.domain.com/admins/accounts/search?search=email%3A{{emai..." target="_blank">
{{ email_address }}
> </a>
> </p>

And this fails:

> <p>2.0 Email Search:

> <a href="https://our.domain.com/admins/accounts/search?search=email%3A{{emai... | escape }}" target="_blank">
> {{ email_address }} 
> </a>
> </p>

thoughts?

November 09, 2013 22:33
User photo
James Dietrich
Zendesk

Hi Andrew,

The Apps Framework uses Handlebars to handle templating logic, so I wouldn't expect Liquid filters to work properly (if at all) in the context of an app template. That said, Handlebars automatically HTML-escapes strings passed into templates, so you shouldn't need to use a filter if that's all you're looking for. From the Handlebars documentation:

Handlebars HTML-escapes values returned by a {{expression}}. If you don't want Handlebars to escape a value, use the "triple-stash", {{{.

If you need to URL-encode data, consider using the encodeURIComponent() Javascript function on your string before passing it to the template.

November 10, 2013 06:21
User photo
Andrew

thanks James - 

If Handlebars is escaping strings automatically, it must be doing an  encodeURI()  or something equivalent as it passes a few things unescaped ( + @  for example)

I came to the same conclusion as you did regarding encodeURIComponent() last night;  it's less elegant as I need to have two versions of the variable (email in this case), but it seems to work.   

November 10, 2013 08:27
User photo
Marla
Yotpo

Hi,

I've been trying to customize the modern template and I'm having a hard time customizing the \{{content}}  placeholder.

I've tried using liquid markup to replace the style elements in the placeholder and was successfull in changing the font size and color but not with the font-family. I copied the font -family found in the source of the email exactly and tried to change it to Arial but it doesn't work with the first response email or it only affects part of the <p></p> elements:

code I used (without the backslash) is:

 

\{%if content contains "font-family: 'Lucida Sans Unicode','Lucida Grande','Tahoma',Verdana,sans-serif"%}
\{{content | replace: "font-family: 'Lucida Sans Unicode','Lucida Grande','Tahoma',Verdana,sans-serif;", "font-family: Arial, Helvetica, sans-serif;" | replace: "font-size: 14px;", "font-size:13px;" | replace: "color:#2b2e2f;", "color:#6b6d6e;"}}

\{%else%}

\{{content}}

\{%endif%}

 

January 23, 2014 08:19
User photo
Marla
Yotpo

I added the backslashes above because I though it would run the code :

The code is:

{%if content contains "font-family: 'Lucida Sans Unicode','Lucida Grande','Tahoma',Verdana,sans-serif"%}
{{content | replace: "font-family: 'Lucida Sans Unicode','Lucida Grande','Tahoma',Verdana,sans-serif;", "font-family: Arial, Helvetica, sans-serif;" | replace: "font-size: 14px;", "font-size:13px;" | replace: "color:#2b2e2f;", "color:#6b6d6e;"}}

{%else%}

{{content}}

{%endif%}

 

January 23, 2014 08:20