Skip to main content

Twig syntax basics

Editing Templates

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.


You insert a variable into a template with double curly braces:


There are dozens of variables available for Deskpro.

Here are some examples:

  • the subject line of the current ticket
  • 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 }}

but that does not work in templates.


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 portal page:

{% if %}
  <p>You are logged in.</p>
{% endif %}

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 portal templates for displaying a list of items
  • {% include %} - includes the content of one template within another

See the official Twig documentation at for more information about what tags can do.


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 #}

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, here’s

{# this comment wraps the code below
  {% for item in navigation %}
      <li><a href="{{ item.href }}">
      {{ item.caption }}</a></li>
  {% endfor %}


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.

Authors list

First published: 23/03/2017

Last updated: Oct 27, 2017 by Paul Davies