Question
How can I reveal CCs in a notification email using Liquid markup?
Answer
While there are many pieces of information to display in notifications, one of the most common requests is the ability to display who else is CCed on a particular request.
Using Liquid markup to display CCs
Liquid markup makes this quite simple. Add this block of code to any triggers or automations in which yo want CCs to be listed:
{% if ticket.cc_names != empty %}
{% capture ccedusers %}
{% for cc in ticket.ccs %}
{% unless forloop.last %}
{{ cc.email | append: ', ' }}
{% else %}
{{ cc.email }}
{% endunless %}
{% endfor %}
{% endcapture %}
{{ ccedusers | strip_newlines }}
{% else %}
Nobody
{% endif %}
This only lists the CCs by email address. Add some text to clarify that these email addresses belong to users who are CCed on this request, as well as any further formatting.
Below you can see how this renders in the email client:
Breaking it down
Make sure that if there aren't any CCs on the request that you don't just leave an empty line. Start by wrapping the code in an If...Else statement to print Nobody if the ticket doesn't have any CCs, and to list those CCs if it does.
{% if ticket.cc_names != empty %}...
{% else %}Nobody
{% endif %}
If the request does have some CCs, grab them and apply some formatting to prevent them from all being globbed together. Start by creating the ccedusers variable to hold all of the CC'ed email addresses with some of our formatting applied so that we can easily reference them later.
{% capture ccedusers %}
...
{% endcapture %}
Iterate over all of the CCs on the ticket, grab the email address for each, and add them to our email variable separated by a ', ' (for all but the last CC) to make them more readable.
{% for cc in ticket.ccs %}
{% unless forloop.last %}
{{ cc.email | append: ', ' }}
{% else %}
{{ cc.email }}
{% endunless %}
{% endfor %}
Print out the freshly constructed list of email addresses. We do this with the following line, making sure we strip the newline characters that would otherwise list each email address individually on its own line.
{{ ccedusers | strip_newlines}}
Alternatives
To include the CCed names, use the following code:
{% if ticket.cc_names != empty %}
{% capture ccedusers %}
{% for cc in ticket.ccs %}
{% unless forloop.last %}
{{ cc.name | prepend: '"' | append: '" '}} {{ cc.email | prepend:'<' | append: '>, ' }}
{% else %}
{{ cc.name | prepend: '"' | append: '" '}} {{ cc.email | prepend:'<' | append: '>' }}
{% endunless %}
{% endfor %}{% endcapture %}
{{ ccedusers | strip_newlines | replace:'"','"' | replace:'<','<' | replace:'>','>' | replace:';','' }}
{% else %}
Nobody is CC'd
{% endif %}
For a complete list of placeholders available to you, please refer to our Placeholders Reference. For more information about Liquid markup, see Liquid for Designers.
44 Comments
If you want them to appear on multiple lines, and you wanted your custom text to only show if there are actual CC's, and you wanted even your own agents to show up as being CC'd, I would do this:
The first line is just standard "CC E-mail" text. You can remove it if you don't want it.
Keep in mind the lines that append and prepend are used for housekeeping. It basically changes something like:
John Smith jsmith@domain.com
to
"John Smith" <jsmith@domain.com>
which is more in line with standards. And the lines that replace is because I found it sometimes to show the word """ so it changes it to just an actual " sign.
Thanks Eli.
Question: when there are no CC'd persons in the ticket, your code is automatically hidden. Thats great!
But that does leave some unnecessary white space (enters) behind which isn't very neat.
Is it somehow possible to remove this side-effect?
Resurrecting the thread. I'm trying to add a tag in the ticket if CC field is not empty. Following code is being called but not working.
{% if ticket.cc_names != empty %}
{“ticket”: {“additional_tags”: [“cc_true”]}}
{% else %}
{% endif %}
HTTP Target - https://mysubdomain.zendesk.com/api/v2/tickets/update_many.json?ids={{ticket.id}}
Have also tried in place of {% if ticket.cc_names != empty %} with no success.
{% if ccedusers != empty %}
or
{% if ccedusers contains '@' %}
Any idea...
Hi,
Is there any way to filter by organization?
I only want one organization to recieve the CCs to try for a few weeks and have some feedback.
I've tried adding {% if user.organization.name contains 'XXXX' %}
but it's not working
thanks!!
Why not change the first "unless" to an "if", like this (taken from my post 3 years ago):
Hello, Is there a way to modify message body of the requester to receive different from the one sent to CC email thru this liquid markup?
something like:
Message to requester: "Your request has been updated."
Message to CCs: "You were copied on this ticket."
Hey Donald Cornel
You can actually avoid Liquid entirely here. You can configure the CC template independently of whatever you send to Requesters. The template control for CCs is found under your admin panel, under the 'Tickets' Section.
Hi Dan,
I guess there is no CC template once 'Ccs and Followers' is enabled, right?
Hi Dan,
What I can see from the Tickets settings, only Followers has email template that can be modified.
For CCs there's none.
@Donald and Thomas,
That is correct. You'd need to edit the trigger instead that would be sending out the CC notification.
Thanks @Brett for confirmation.
Anyone has an idea how to customize the message for all CCs only?
Greetings folks,
When using the markup and recommended changes to hide email addresses:
{% if ticket.cc_names != empty %}
{% capture ccedusers %}
{% for cc in ticket.ccs %}
{% unless cc.email contains 'tnsinc.com' %}
{% unless forloop.last %}
{{ cc.name | prepend: '"' | append: '" '}} {{ cc.email | prepend:'<' | append: '>, ' }}
{% else %}
{{ cc.name | prepend: '"' | append: '" '}} {{ cc.email | prepend:'<' | append: '>' }}
{% endunless %}
{% endunless %}
{% endfor %}
{% endcapture %}
{% if ccedusers contains '@' %}
People CC'd on this ticket:
{{ ccedusers | strip_newlines | replace:'"','"' | replace:'<','<' | replace:'>','>' | replace:';','' }}
{% endif %}
We get the error that:
Trigger could not be updated:
Any ideas? We want to be able to show only when folks are cc'd and hide agent email addresses
Jason
You are missing the final {% endif %} on the last line of your code. So the last 2 lines should be:
{% endif %}
{% endif %}
Thank you Graeme Carmichael
Apparently, my morning coffee is not leaded enough.
You are appreciated!
Please sign in to leave a comment.