Skip to main content

Variables in custom phrases

Editing Templates

You can’t use the standard variables that you would use in a template in a phrase. For example, if you include {{ ticket.agent.display_name }} in a custom phrase, it will not be replaced with the agent’s name, as it would be in a template.

You can access variable content from your custom phrases, but you don’t include the variable in the custom phrase directly.

Instead, you define a phrase variable that applies only within the custom phrase, then when you include the phrase in a template, you pass the value of the standard variable to the phrase variable.

For example, suppose you have created a custom phrase called which you want to reference the name of the currently assigned agent.

We’ve already said that you can’t include the usual {{ ticket.agent.display_name }} variable.

Instead, you’d include a phrase variable, like this:

<p>Your ticket has been assigned to {{agent-name}}.</p>

{{agent-name}} is the phrase variable. The choice of the ‘agent-name’ part is arbitrary - we could have called it {{name}} or {{agent}} or {{var}} (but it’s better to pick a meaningful name in case you or someone else comes back to edit the phrase later). The important thing is that you use the same name when you’re referencing the phrase in your template, as we will see.


Unlike standard variables, the phrase variable should not have a space between the curly brackets and the name; {{agent-name}} will work, but {{ agent-name }} will not.

In your email template, instead of referencing the custom phrase the usual way, like this:

{{ phrase('user.emails.greeting') }}

you would do this:

{{ phrase('', { agent-name:
ticket.agent.display_name }) }}

When an email is sent using the template, this passes the current value of ticket.agent.display_nameto the {{agent-name}} variable within the custom phrase.

Custom phrase with multiple variables

Of course, a custom phrase may contain more than one phrase variable.

Say your custom phrase contains both {{agent-name}} and {{id}} as phrase variables. In your template, you would write:

{{ phrase('', { agent-name:
ticket.agent.display_name, id: }) }}``
Authors list

First published: 23/03/2017

Last updated: 23 Mar 2017 by Colin Dunn