The templating system Deskpro uses is called Twig.
Below are the features you’ll need to know to do the most common forms of customization.
Variables
You insert a variable into a template with double curly braces:
{{variable}} copy
There are dozens of variables available for Deskpro.
Here are some examples:
{{ticket.subject}} copy
The subject line of the current ticket.
{{ticket.agent.display_name}} copy
The name of the Agent assigned to the current Ticket (or their override name if one is set).
Note that in snippets and trigger actions, you have to put spaces before and after the variable name, like this:
{{ variable }} copy
but that does not work in templates.
Custom Fields
Custom ticket fields can be inserted into templates using the below variable. Make sure to replace '#' with the custom field ID number.
{{ render_ticket_custom_field(ticket, #, 'text') }} copy
For user custom fields you can use:
{{ render_person_custom_field(ticket_person, #, 'text') }} copy
Tags
Twig also includes tags which control the logic of the template.
For example, the {% if %}
tag lets you have a section of your template that only displays if a certain condition is met.
This code on a Help Center page:
{% if app.user.id %}
You are logged in.
{% endif %} copy
would display the text “You are logged in” if the template could retrieve a User ID - i.e. if the User is logged in.
Other useful tags you will see in templates:
{% else %}
- used in conjunction with{% if %}
to display content if its condition is not met.{% for %}
- creates a loop while a certain condition is met; you’ll see this used in Help Center templates for displaying a list of items.{% include %}
- includes the content of one template within another.
See the official Twig documentation at https://twig.symfony.com/doc/3.x/ for more information about what tags can do.
Comments
You can leave comments to explain what your custom templates do. Comments will not affect how the template works; they are just for human reference.
{# this is a comment #} copy
When you’re troubleshooting a template, or trying to understand how the built-in templates work, it’s useful to comment out a section of code to quickly disable it, and see how the template behaves without it. For example:
{# this comment wraps the code below
{% for item in navigation %}
{{ item.caption }}
{% endfor %}
#} copy
Don’t use HTML comments within templates. If there are comments in a piece of inserted HTML, the two sets of comments can interact and mangle the intended HTML.
Please log in or register to submit a comment.