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

Return to top
Have more questions? Submit a request

22 Comments

  • Thomas Joussot

    This might sound like a dummy question but is there any advantage using Liquid markup in such a case instead of Dynamic Content when dealing with multiple langages ?

    1
  • Adam Reid

    Hi Aimee,

    Thanks for this wonderful example with Liquid markup. I've tried using your example but it always defaults to the last else statement.

    Are you using the short or long versions of the language codes?

    0
  • Adam Reid

    This is currently what I'm using and it's returning only the last else.

    {% case ticket.requester.language %}

    {% when 'Japanese' %}

    Ciao {{ticket.requester.first_name}} - Japanese

    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}}


    {% when 'Spanish' %}

    Hej {{ticket.requester.first_name}} - Spanish

    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}}


    {% 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}}


    {% endcase %}
    0
  • Brett Bowser
    Zendesk Community Team

    Hey Adam,

    It looks like when specifying the locale name you need to do so in the local language. For example, Danish would be Dansk. If you take a look at the following comment by one of our community members it looks like you can capture this information using the API: Understanding Liquid markup and Zendesk Support

    Additionally, you may want to look into using Dynamic Content to provide multiple language support. This wouldn't require you to set up multilingual support via Liquid Markup and may save you a bit of a headache down the road.

    Hope this helps!

    0
  • Adam Reid

    Hey Brett,

    Thanks for your reply. That example worked perfectly. After running the API call I got these outputs and was able to grab the exact keyword to match.

    0
  • Brett Bowser
    Zendesk Community Team

    Happy to help Adam :)

    0
  • David Seinsche

    "It looks like when specifying the locale name you need to do so in the local language." -> This should be included in the example written by Aimee Spanier to avoid confusion and frustration. 

     

    0
  • Amauri Souza

    Hi,

     

    how can I use liquid to build a json with a ticket data, such as attachments and URL?

     

    I tried to do so with the following code, but it did not work:

    {
    "msg": "{{ticket.title}} received from {{ticket.requester.name}}",
    "comentarios": "{{ticket.comments}}",
    "anexos": [

    {% for comment in ticket.comments %}
    {% unless forloop.last %}
    "anexo": "{{comment.attachment.url}}",
    {% endunless %}
    {% if forloop.last %}

    "anexo": "{{comment.attachment.url}}"

    {% endif %}
    {% endfor %}

    ]}

    It just doesn't send the data and I can't see what errors occurs



    0
  • Andreas Schuster
    Community Moderator

    Hi Amauri Souza,

    You could embed the code into a macro, which will execute it.
    After that please share the content so that we can see if it's valid JSON.

    0
  • Amauri Souza

    Hi, thank you for your reply!

    I solved the problem with the following code:

    {
    "msg": "{{ticket.title}} received from {{ticket.requester.name}}",
    "comentarios": [
    {% for comment in ticket.comments %}
    {% unless forloop.last %}
    {
    "authorName": "{{comment.authorName}}",
    "value": "{{comment.value}}",
    "anexos": [
    {% for attachment in comment.attachments %}
    {% unless forloop.last %}
    {
    "url": "{{attachment.url}}",
    "fileName": "{{attachment.filename}}"
    },
    {% endunless %}
    {% if forloop.last %}
    {
    "url": "{{attachment.url}}",
    "fileName": "{{attachment.filename}}"
    }
    {% endif %}
    {% endfor %}
    ]
    },
    {% endunless %}
    {% if forloop.last %}
    {
    "authorName": "{{comment.authorName}}",
    "value": "{{comment.value}}",
    "anexos": [
    {% for attachment in comment.attachments %}
    {% unless forloop.last %}
    {
    "url": "{{attachment.url}}",
    "fileName": "{{attachment.filename}}"
    },
    {% endunless %}
    {% if forloop.last %}
    {
    "url": "{{attachment.url}}",
    "fileName": "{{attachment.filename}}"
    }
    {% endif %}
    {% endfor %}
    ]
    }
    {% endif %}
    {% endfor %}
    ]
    }
    1
  • Dan Cooper
    Community Moderator

    Edit: You beat me to it.  Congrats on finding a solution and thanks for sharing! 

    It appears that you are trying to iterate through your comment and display all of the article attachments as part of the body.  This article shows how you could parse out individual attachments from a comment to clean up your liquid markup logic.  

    I took a stab at making this work but made an assumption about only sending the last comment as everything was blending together without spacing when I used your original ticket.comments placeholder.  You might need to adapt the logic here: 

    {
    "msg": "{{ticket.title}} received from {{ticket.requester.name}}",
    "comentarios": "{{ticket.latest_comment}}",
    "anexos": [

    {% for comment in ticket.comments %}
    {% for attachment in comment.attachments %}
    {% unless forloop.last %}
    "anexo": "{{attachment.url}}",
    {% endunless %}
    {% if forloop.last %}
    "anexo": "{{attachment.url}}"
    {% endif %}
    {% endfor %}
    {% endfor %}
    ]}

    I didn't quite get this fully working before running out of time to dive into this, but one thing I noticed is that the logic I'm working through is parsing through attachments on all comments, so the unless statements aren't working right here to apply the commas in the right place because I'm still iterating through each comment so the for loop is resetting each time. So that will have to be shored up, but I can get all of the urls this way. It needs a bit more work, but I'm seeing these expand in a JSON body trigger to target test so I think it might give you some ideas on how to proceed with liquid and placeholder adjustments. 

    1
  • Amauri Souza

    Thank you anyway, it's great to know that I can count on guys like you and Andreas that helped with great information. I will probably have more doubts future.

    0
  • Jason Littrell

    Amauri Souza Just adding a couple of things.

    First, you can avoid some duplication of code by wrapping an "unless" block around only the commas inside the "for" loops:

    {
    ...
    "comentarios": [
    {% for comment in ticket.comments %}
    {
    ...
    "anexos": [
    {% for attachment in comment.attachments %}
    {
    ...
    }{% unless forloop.last %},{% endunless %}
    {% endfor %}
    ]
    }{% unless forloop.last %},{% endunless %}
    {% endfor %}
    ]
    }

    Second, "comment.authorName" isn't a valid placeholder, but the "comment.author" is a full user object so you have access to all the user properties. That means you can use "comment.author.name", as well as other properties like "first_name", "last_name", "email", "id", etc.

    0
  • Oliver Tietze

    According to the Liquid documentation, there are these filters:

    Unfortunately, none of them seems to work within Zendesk, what are we missing here?

    Kind regards,
    Oliver

    2
  • Alejandro Colon

    Oliver Tietze

    Were you able to find an answer to the missing filters using Liquid?

    0
  • Greg - Community Manager
    Zendesk Developer Support Team

    Hi all! At Zendesk, we are accessing the open source Liquid project that Shopify has graciously provided to the community. If you check the link that I provided, the filters that you're accessing are not available through the open source project and thus we do not have access to them. The link that shows the properties is directly connected to the Shopify API, which clearly has a more robust feature set.

    You could make a request on their Github repo to add that functionality into the open source project, but that is the reason that it currently does not work here.

    1
  • Alejandro Colon

    Greg - Community Manager

    Thanks for letting us know. 

     

    I have requested that they bring some of their more useful filters over to the main language.

     

    https://github.com/Shopify/liquid/issues/1253#issue-622785461

    0
  • Greg - Community Manager
    Zendesk Developer Support Team

    Great, thanks for doing that!

    Greg Katechis | Developer Support and Enablement Engineer

    0
  • Rom Hirsh

    I have been attempting to copy the comment text (last comment) from one ticket and create another. It's working fine except for the formatting of the comment. I seem to be losing HTML tags and content while calling the new ticket API request.

    I tried to structure the 'html_body' using {{ticket.latest_comment_formatted}} as well as with DC like:

    {% for comment in ticket.comments limit:1 offset:0 %}
    {{comment.value_rich}}
    {% for attachment in comment.attachments %}
    {{attachment.filename}}
    {{attachment.url}}
    {% endfor %}
    {% endfor %}

    But I am losing the original comment formatting in the process - has anyone been able to copy the last comment with formatting and attachments over API?

     

    Example comment (converted to HTML)

    <p>Hi Ops,&nbsp;<br /><br />Please configure the following Account&nbsp;<br /><br /><br /></p>
    <table>
    <tbody>
    <tr>
    <td><strong>Account Type</strong></td>
    <td>Marketing</td>
    </tr>
    <tr>
    <td><strong>Brand Name</strong></td>
    <td>bla bla</td>
    </tr>
    <tr>
    <td><strong>Tenant Name</strong></td>
    <td>blibli EU</td>
    </tr>
    <tr>
    <td><strong>Sendgrid link for OpS</strong></td>
    <td>(Username, Password, API key)&nbsp;<a href="https://pwd.bliblo.net/" target="_blank" rel="noopener noreferrer">https://pwd.bliblo.net/</a></td>
    </tr>
    <tr>
    <td><strong>Email Field</strong></td>
    <td>STR63</td>
    </tr>
    </tbody>
    </table>
    <p><br /><br />Please reply once it is successfully configurated.<br /><br />Thanks,&nbsp;<br />Roni</p>
    <p>&nbsp;</p>
    0
  • Giuseppe
    Zendesk Customer Advocate

    Hi Rom,

    It's possible that {{comment.value_rich}} is not returning an HTML formatted value because it is under ticket.comments, which displays all the comments in a ticket in unformatted text. See Comment Data

    Instead, could you try using {{ticket.latest_public_comment}} or {{ticket.latest_public_comment_rich}}?

     

    On another note, you may want to check the Linked Ticket app in our Marketplace and see if this also helps with your workflow.

     

    Thanks!

    0
  • Rom Hirsh

    Giuseppe

    I tried these as well but still, I cannot get HTML to render while updating the ticket via HTML. The use of the linked tickets app is not good for me as it required much manual work and I am trying to automate this. 

    Any other suggestions? 

    0
  • Giuseppe
    Zendesk Customer Advocate

    Hi Rom Hirsh

    I'll be creating a ticket for your query and send an email to you so we can investigate further.

    Thanks!

    0

Please sign in to leave a comment.

Powered by Zendesk