Using Liquid markup to reveal CCs in a notification email Follow

Comments

20 comments

  • Avatar
    Tiina Moilanen

    Hi Matt,

    It doesn't look nice for customer to see text below:

    "CCs on Ticket:

    Nobody"

    Is it possible to modify code so that if there is not CC's on ticket, there's not this text at all? But when there's CC's, then text appears naturally.

    Do you have tips how to code this?

  • Avatar
    Matt Sirianni

    Tiina,

    Absolutely. You'd simply move the 'CCs on Ticket:' text into/below the following if block:

    {% if ticket.cc_names != empty %}

    Finally, delete the 'Nobody' in the {% else %} clause.

  • Avatar
    Tiina Moilanen

    Hi Matt,

    I'm using Dynamic content, because we've 5 different languages and Dynamic content isn't working inside the code.

    How can I create code to support these 5 languages?

    The code that I have right now is this:

    {{dc.aa_ccs_on_ticket}} <-dynamic content supported by 5 languages

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

    -

    {% endif %}

    BR,

    Tiina

  • Avatar
    Ace Coven (Edited )

    Matt, thanks for this great explanation. I read up on Liquid and the {% for %} loop actually does its own check for empty and guarantees it will only iterate over the items if they exist. In fact, you can add an {% else %} to the {% for %} loop to put your "Nobody" in the main loop if it's got no items.

    There's an additional optimization. You're using prepend and append on cc.name and cc.email, which are guaranteed to exist, right? Also, you don't need to double the entire output for the {% else %} block, when all you really need to do on the last iteration is NOT add the ", ".

    Taking all these optimizations together, you'd shorten your code quite a bit to:

    {% capture ccedusers %}
    {% for cc in ticket.ccs %}
    "{{ cc.name }}" <{{ cc.email }}>
    {% unless forloop.last %}, {% endunless %}
    {% else %}
    "Nobody" <nobody@nobody.com>
    {% endfor %}
    {% endcapture %}
    {{ ccedusers | strip_newlines | replace:'"','"' | replace:'&lt;','<' | replace:'&gt;','>' }}

    And, like others have mentioned, this display is only for readability and comprehension. When you actually put this in your Dynamic Content editor, put it in as:
    {% capture ccedusers %}{% for cc in ticket.ccs %}"{{ cc.name }}" <{{ cc.email }}>{% unless forloop.last %}, {% endunless %}{% else %}"Nobody" <nobody@nobody.com>{% endfor %}{% endcapture %}{{ ccedusers | strip_newlines | replace:'"','"' | replace:'&lt;','<' | replace:'&gt;','>' }}

    Hope this helps!

  • Avatar
    Emilie Vittini

    Hi Everyone, 

    Thank you for your comments, it's been very helpful!

    I copied and paste the last code that Ace posted. Would you know how to remove the "Nobody" <nobody@nobody.com> when no one is copied?

    Thanks for your help :)

     

  • Avatar
    Ace Coven

    @Emilie: Just remove these two lines:

    {% else %}
    "Nobody" <nobody@nobody.com>

    I just added them as an example of the "else" clause, you don't need it if you're not wanting always at least someone Cc'ed.

    Cheers,

    ...A

  • Avatar
    Johan

    Hello everyone,

    I'm currently using this for our user notification triggers however it changes the font color for the some parts of the text, please view the below example:

    Has anyone encountered the same issue and come up with a solution?

    Note: I'm using the default email template.

    Cheers!

  • Avatar
    Eli Webster

    Hello, there is actually a mistake in the article above. The article recommends inserting the following line if you had lines above showing the name of the CC'd user along with the e-mail:

    {{ ccedusers | strip_newlines | replace:'&quot;','"' | replace:'&lt;','<' | replace:'&gt;','>' }}

    The issue is that if you go back into the trigger, you will see it converts the line to this (it's converting the code into actual characters):

     {{ ccedusers | strip_newlines | replace:'"','"' | replace:'<','<' | replace:'>','>' }}

    Therefore, instead you can use this line - tested and working!

     {{ ccedusers | strip_newlines | replace:'&quot','"' | replace:'&lt','<' | replace:'&gt','>' | replace:';','' }}

  • Avatar
    Darrell Watts (Edited )

    I have tried using this Liquid code for CC's on my tickets.  Although the logic appears to work as in it knows there are other people cc'd it doesn't show any details for them.

    Andy idea why this will be the case ?

  • Avatar
    Matt

    Hi All,

    I'm using the method described here to add CC'd parties to my tickets, and 'not show' if there are no CC's

    Here is the code I have modified -

    {% if ticket.cc_names != empty %}The following email addresses are copied on this ticket - {% capture ccedusers %}{% for cc in ticket.ccs %}{% unless forloop.last %}{{ cc.email | append: ', ' }}{% else %}{{ cc.email }}{% endunless %}{% endfor %}{% endcapture %}{{ ccedusers | strip_newlines }}{% else %}{% endif %}

    The challenge I have is that it shows the 'personal' emails of our support team when they CC themselves...., which I would like to avoid, as this could cause customers to try to reach out to individual agents via direct email, instead of our main support channel.

    I'm wondering if there is a way with Liquid to, for example, 'not show email addresses which end in '@mydomain.com' ?

    Or any other suggestions you may have here?

  • Avatar
    Eli Webster

    @Matt, of course. Here you go:

     

    {% if ticket.cc_names != empty %}
    People CC'd on this ticket:
     {% capture ccedusers %}

     {% for cc in ticket.ccs %}
     {% unless cc.email contains 'yourdomain.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 %}
     {{ ccedusers | strip_newlines | replace:'&quot','"' | replace:'&lt','<' | replace:'&gt','>' | replace:';','' }}
    {% endif %}
  • Avatar
    Matt

    Legend Eli, thank you.  I owe you a beer! (or wine?)

    It works well except for one edge case - where the 'only' cc's on the ticket are @mydomain.com email addresses.

    In that case, the 'People CC'd on this ticket' text shows correctly (as there are CC's), but there are none listed (as the only ones CC'd are hidden)

    I'm sure there is a way to beat that too.... thoughts?

    Must get to know this Liquid Markup better :)

     

  • Avatar
    Eli Webster (Edited )

    Hmm...yeah I see that happening by me as well. I imagine we can do a for loop first that checks whether or not yourdomain.com shows up in a CC and if not, set a variable to "1", and only if the variable is "1" at the end, should we display the CC's. It's 12:30am though and I don't have the head to code that now, but it's some food for thought.

    Maybe, instead of putting the "People CC'd on this ticket:" in the beginning, we can save it for the end, and do something like this:

    {% if ccedusers != empty %}
    People CC'd on this ticket:
    {{ ccedusers | strip_newlines | replace:'&quot','"' | replace:'&lt','<' | replace:'&gt','>' | replace:';','' }}
    {% endif %}
  • Avatar
    Eli Webster

    Hey @Matt, I figured it out! Thanks for challenging me to do this, because it bothered me also that it would say "People CC'd on this ticket:" and then not show any names. So here you go:

    First, remove "People CC'd on this ticket:" from the top part of the code, then...

    Replace this:

     {{ ccedusers | strip_newlines | replace:'&quot','"' | replace:'&lt','<' | replace:'&gt','>' | replace:';','' }} 

    with this:

    {% if ccedusers contains '@' %}
     People CC'd on this ticket:

     {{ ccedusers | strip_newlines | replace:'&quot','"' | replace:'&lt','<' | replace:'&gt','>' | replace:';','' }}
    {% endif %}
  • Avatar
    Matt (Edited )

    Eli, that's two beers I owe you.  Thanks! Glad it helped your implementation too :)

     

    If you're in Sydney one day soon, look me up!

  • Avatar
    Eli Webster

    Glad it worked out for you. I’m across the world in Chicago, but ya never know...

    Have a good one “mate”!

  • Avatar
    Jennifer Zou (Edited )

    Hi Everyone,

    I want to copy old ticket's CCs to the new tickets, how can I do this with JSON?

    My JSON:

    {
    "ticket": {
    "subject":"{{ticket.title}}",
    "description":"{{ticket.description}}",
    "type":"{{ticket.ticket_type}}",
    "priority": "{{ticket.priority}}",
    "tags":"{{ticket.tags}}",
    "status": "{{ticket.status}}",
    "comment":"{{ticket.comments_formatted}}",
    "requester": { "name": "{{ticket.requester.name}}", "email": "{{ticket.requester.email}}" },
    "collaborators":["{% capture ccedusers %}{% for cc in ticket.ccs %}{% unless forloop.last %}{{ cc.email | append: '", "' }}{% else %}{{ cc.email }}{% endunless %}{% endfor %}{% endcapture %}{{ ccedusers | strip_newlines }}{% else %}{% endif %}"]
    }
    }

    This doesn't work...

    I also tried.. "collaborators":["{% for cc in ticket.ccs %}{% unless forloop.last %}{{ cc.email | append: '",' }}{{ cc.email }}{% endunless %}{% endfor %}"]

  • Avatar
    Eli Webster

    I'm sorry @Jen, but I don't really understand what you are trying to accomplish here. Perhaps explain a bit more?

  • Avatar
    David Allegretti

    Folks, thanks for all this great information.  Below I have the code we are using to reveal CC's, but in the actual emails, there is too much unnecessary empty space after the line "This ticket has been updated" and before the words "People CC'd on this ticket".  How can I remove that spacing?

    This ticket () has been updated.



    People CC'd on this ticket:
    blah@blah.com
    ---------------------------

    CODE:

    This ticket (#{{ticket.id}}) has been updated.
    {% 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 %}
     {% if ccedusers contains '@' %}
     People CC'd on this ticket:
     {{ ccedusers | strip_newlines | replace:'&quot','"' | replace:'&lt','<' | replace:'&gt','>' | replace:';','' }}
     {% endif %}
    {% endif %}
    {{ticket.comments_formatted}}

     

     

  • Avatar
    Eli Webster

    It doesn't look like you have any extra lines in your code, but the extra lines are what would cause the white space. There is some white space built in on top of the {{ticket.comments_formatted}} but shouldn't be that much. Make sure there are no spaces or tabs at the end of these lines:

     People CC'd on this ticket:
     {{ ccedusers | strip_newlines | replace:'&quot','"' | replace:'&lt','<' | replace:'&gt','>' | replace:';','' }}
     {% endif %}
    {% endif %}

    Actually, you should check EVERY line to make sure there's no extra spaces or tabs, and keep the code tight.

Please sign in to leave a comment.

Powered by Zendesk