By default, many 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.created_at_with_time}} {{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.
{% 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.
For more information on how Liquid markup can be used, see Understanding Liquid markup and Zendesk Support.
11 comments
Federico Olmus
Here is a related article that might also be relevant: Setting up an unformatted email template
Thank you Aimee!
0
Roman Sheydvasser
Fyi, if you're looking for information about how to do visual formatting / styles with Liquid markup, it's just plain html.
To bold something: <b>bold</b>
To make something into a heading: <h1>heading</h1>
0
Amanda Fleet
This was incredibly helpful! Thank you!
1
Jed Hollander
Hi there, Aimee Spanier
Is there a way to clean up this markup
{% for comment in ticket.comments %}
Comment:
{{comment.created_at}}
{{comment.created_at_with_time}}
{{comment.author.name}}
{{comment.value}}
Attachment:
{% for attachment in comment.attachments %}
{{attachment.filename}}
{{attachment.url}}
{% endfor %}
{% endfor %}
to only include the URL's for all the attachments in public comments but not the comments? The above returns all comments without an attachment as well and I'm having trouble editing it.
Thanks!
1
Carly Adams
Hi,
And thanks for the article.
Is there a way to pass the text so it is formatted like a ticket and not just text?
I am creating a forwarding email and would like to replicate the ticket but send it to a different requester.
0
Zsa Trias
Hello Carly,
You may want to check this article on how you can customize your email template: Customizing your email templates for notifications
0
Scott Tynan
Jed Hollander MS Copilot said this about your question.
Sure, I can help with that. If you only want to include the URLs for all the attachments in public comments and not the comments themselves, you can modify your code to look like this:
This will loop through all the comments and their attachments, but only print out the URLs of the attachments. It will not print out any information about the comments themselves or any attachments without a URL. This should give you a cleaner output with only the information you want.
0
Vicky
im trying to change the {{comment.author.name}}, if the author is an agent, it would be a fix name, but when its an end user it would be as their name on zendesk, if there a way to do it ?
0
Vlad
Hey Vicky, have you tried like:
{{#if author.agent}}
fixed name
{{else}}
{{author.name}}
{{/if}}
0
Vicky
Vlad
It works at the beginning, but when the end user replied, it still shows the Fixed name, and the content all mixed together,
the below is what i had
{% for comment in ticket.comments %}
<hr/>
{{#if author.agent}}
<b>Fix Name</b>
{{else}}
{{author.name}}
{{/if}}
<span style="color: #999999;"> {{comment.created_at_with_time}}<br /></span>
{{comment.value}}
{% endfor %}
0
Carly Adams
Hi, I think I wasn't clear in my last comment.
In sted of {{comment.value}} I need something like {{ticket.comment_html_body}}
This way, it is formatted correctly and will display images and more.
how do I do this?
1