Using Liquid markup to reveal CCs in a notification email Follow

Comments

9 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 ?

Please sign in to leave a comment.

Powered by Zendesk