Skip to main content

Common Email Conversion Code Replacements - Knowledgebase / Using Deskpro / Admin - Deskpro Support

Common Email Conversion Code Replacements

Authors list

This article is designed to help anyone who has enabled our new Email Templates and is required to manually convert some customized templates from the legacy email template system.


The new templates use different code snippets to insert certain pieces of data into the emails (for example agent messages or the ticket history table used in agent notification emails), so in some cases where you have copied and re-used code from default email templates into custom ones, copying and pasting code from the old template directly into the new template won't necessarily work. 


Here are some examples of code snippets commonly used in legacy email templates and the code equivalent that you need to use in the new templates instead wherever the old code has been used in custom templates. After pasting the code snippets into the editor, please use the Preview function to ensure that the code is working as expected and displays the intended content.


Agent Reply:

Used in emails sent to a user when an agent replies to their ticket.

Old:

<dp:agent-reply />


Replace with:

{% set message = ticket_messages|first %}

{% if message.person.is_agent %}

        {% include 'SendmailBundle:emails_common:ticket_message_agent.html.twig' %}

{% else %}

        {% include 'SendmailBundle:emails_common:ticket_message.html.twig' %}

{% endif %}


Custom Field Variables:

 Used to display the value of a custom field in an email. In these examples, # represents the ID number of your custom field). 

Old:

Ticket custom field: {{ticket.renderCustomField(#) | raw}}

Person custom field: {{ ticket.person.renderCustomField(#) | raw }} 

Organization custom field: {{ ticket.person.organization.renderCustomField(N) | raw }} 

or

{{ ticket.renderCustomField(#, 'text') }} 

{{ ticket.person.renderCustomField (N, 'text') }} 

{{ ticket.person.organization.renderCustomField (N, 'text') }}


Replace with:

{{ render_ticket_custom_field(ticket, #) }} 

{{ render_person_custom_field(ticket_person, #) }}

{{ render_organization_custom_field(ticket_person.organization, #) }}

or 

{{ render_ticket_custom_field(ticket, #, 'text') }}

{{ render_person_custom_field(ticket_person, #, 'text') }}

{{ render_organization_custom_field(ticket_person.organization, #, 'text') }}


Please note that these variables display slightly differently. If you want to use the variable within a sentence, we recommend that you use the {{ render_ticket_custom_field(ticket, #, 'text') }}  version.


Portal URL:

Old:

<a href="{{ portal_url }}">{{ portal_url }}</a>


Replace with:

<a href="{{ portal_home }}">{{ portal_home }}</a>


Display Satisfaction Rating Links:

Used in emails sent to a user when an agent replies to their ticket and satisfaction ratings are enabled.

Old:

{% if show_rating_link and app.isPortalEnabled() %}<dp:ticket-rating-links />{% endif %}


Replace with:

    {% if show_rating_link and app.isPortalEnabled() and can_login(recipient.id) %}

        {% set message = reply %}

        {% include 'SendmailBundle:emails_common:ticket_rating_links.html.twig' with {message: message, ticket: ticket} %}

    {% endif %}


View and Manage this Ticket Online Link:

Old:

{% if app.isPortalEnabled() %}

<br /><br />

View and manage this ticket online:

<a href="{{ portal_url(ticket) }}">{{ portal_url(ticket) }}</a>

{% endif %}


Replace with:

    {% if app.isPortalEnabled() and can_login(recipient.id) %}

        <br /><br />


        {{ phrase('helpcenter.emails.ticket_access_ticket_online') }}

        <a href="{{ ticket_link }}">{{ ticket_link }}</a>

    {% endif %}


User Ticket Message History:

History of previous ticket messages used in reply emails sent to users from agents.

Old:

<dp:ticket-history />


Replace with:

    {% for message in ticket_messages|slice(1) %}

        {% if not context.message_limit or loop.index0 < context.message_limit %}

            {% include 'SendmailBundle:emails_common:ticket_message_row.html.twig' with { message: message, ticketdisplay: context.ticketdisplay } %}

        {% endif %}

    {% endfor %}


Agent Ticket Message History:

History of messages used in reply notification emails sent to agents.

Old:

<dp:agent-ticket-history />


Replace with:

    {% if context.is_new_user_reply or context.is_new_agent_reply %}

        {% set messages = ticket_messages|slice(1) %}

    {% else %}

        {% set messages = ticket_messages %}

    {% endif %}

    {% for message in messages %}

        {% if not context.message_limit or loop.index0 < context.message_limit %}

            {% include 'SendmailBundle:emails_common:ticket_message_row.html.twig' with { message: message, ticketdisplay: context.ticketdisplay, show_author_email: true, is_to_agent: true } %}

        {% endif %}

    {% endfor %}


Ticket Properties Table:

Used in agent notification emails. 

Old:

<dp:ticket-properties-table />


Replace with:

 {%  include 'SendmailBundle:emails_common:ticket_props_table.html.twig' %}


Ticket Changes Table:

Used in agent notification emails. 

Old:

<dp:ticket-logs />


Replace with:

{% for log in context.ticket_logs %}

        {% include 'SendmailBundle:emails_common:ticket_log_actiontext.html.twig' %}

    {% endfor %}


If there are any other code snippets that you have used in an email template and you'd like to check the appropriate replacement code to use in the new templates, please contact support@deskpro.com and we'll be happy to advise further.

Helpful Unhelpful

19 of 41 people found this page helpful

Add a comment

Please log in or register to submit a comment.

Need a password reminder?