From Request Tracker Wiki
Jump to: navigation, search

What are Templates in RT?

Template is a text. One Template can be attached to a Scrip, which ScripAction will use the template to get additionaly required information.

Different actions can use templates in different ways or ignore them at all, for example RT's variouse notify... actions use them as template for outgoing email when ExtractCustomFieldValues uses its template to allow you to describe parser that fetches and prepare data before storing it in a CustomField. Read below about notification templates.

Each template has a name and associated with a Queue or can be global. It's possible to override a global template with different version for some queue, read about this below.

How Can I Edit the Templates?

Start by logging in as a privileged user (with the ModifyTemplate, ShowTemplate and ShowConfigTab rights).

Go to the Configuration tab in the WebUI, then choose Global -> Templates. All the global templates are visible from this page. To edit a queue specific template go to Configuration, Queues, pick a queue from the list and then click on Templates tab in the menu.

Selecting any one of the specific template links brings the user to a page with an edit window and the existing template content in the edit-window context. Make any changes and click the "save" button in the bottom-right-hand corner.

Templates for notification actions

RT has by default has several "Notify ..." actions, all of them use template to build outgoing email.

The Text::Template module gives these notification actions a powerful, but simple, template system, allowing you to use inline Perl code to create customized responses based on data from the current transaction, ticket or the whole database.

The template looks something like an RFC822 compliant mail message, with a block of zero or more headers followed by some body text.

The first lines of the template can override mail headers that may already be set in a previous email. If an overriding header is not present at the beginning of the template, then the existing header will be used. For example, if you want all your automated replies to look the same, you can replace the existing "From: " with your own. You can also create your own custom headers to help route tickets, fight spam, and more.

Note: Don't forget to leave an empty line after the headers, otherwise you'll get an unexpected end of header error in the log.

Attaching original attachments to the mail

'RT-Attach-Message: Yes' is a special header that RT uses internally. It means that the outgoing mail should be created with all attachments. Instead of adding attachments to an outgoing email you can add links to those using AddAttachmentLinksToMail.

What fields available in a Template?

Outgoing email templates can have any bit of information you can pull out of RT. Start from TemplateSnippets. Continue with CodeSnippets.

What if I want to override a global template for one of my queues?

Templates are attached to Scrips by name - meaning that if you define a Queue Template with the same name as a Global Template, when a Scrip is triggered it will use the Queue Template instead.

One example would be to create a Queue Template called 'Correspondence'. The various global Scrips that use the Correspondence template will use our new template, not the global template of the same name.

See also

CodeSnippets, Contributions, RTSearchPerlAPI, perldoc lib/RT/Template.pm, perldoc Text::Template