Skip to main content

Variables in Custom Phrases

in Advanced Content Editing
Authors list
Published: 21 Sept 2021|Last updated: 19 Oct 2021

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 custom.ticket.auto-notification-agent in 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>
copy

{{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.

Note


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') }} copy
copy

you would do this:

{{ phrase('custom.ticket.auto-notification-agent', { agent-name: ticket.agent.display_name }) }} copy
copy

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 Copy link to Custom Phrase with Multiple Variables to clipboard

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('custom.ticket.auto-notification-agent', { agent-name: ticket.agent.display_name, id: ticket.id }) }}``
copy
HelpfulUnhelpful
next pageContent Publish Options
previous pageUseful Template Variables

Please log in or register to submit a comment.