Question

How can I format Zendesk placeholders with liquid markup? 

Answer

Use output markup and filters to modify placeholder output. Output markup, such as placeholders, is surrounded by matched pairs of braces, for example, {{ticket.ticket_id}}. A filter is a method that acts on the output markup. The filters modify the output and the result is displayed as a string. The output and the markup are separated by a vertical bar, or "pipe" (|), and the overall format is {{ output | filter: }}.

See all of the standard filters on the Liquid for Designers page. To illustrate the concept, see the following example.

Example: Showing only the last element in nested custom ticket fields

When building custom drop-down fields, you can nest the structure using double colons - "::". For example, if you make a drop-down with options of Support::Password, Support::Performance, Billing::Invoice, and Billing::Refund, the end user will first select either Support or Billing and then choose the options within these categories. You can output custom ticket fields like this in a placeholder, following the format {{ticket.ticket_field_ <field ID number> }}.

However, this default placeholder format does not take nesting into account. The output for the above example is "Billing::Invoice", which shows the double colons. To show the last element only, "Invoice", use two filters in combination. The first filter, called "split", splits the string upon a matching pattern ("::"). The second filter, "last", gets the last element of the passed-in array. To split on "::" , go after the split filter:
{{ticket.ticket_field_<field ID number> | split:"::" | last }}

Tip: The same principle applies if you want to return only the first element of a nested field. Use the "first" filter instead of "last."

For more information, see this article from Github: Liquid for Designers.

Powered by Zendesk