3 Templates are used in RT to send notifications, typically email. You have
4 access to RT data via variables available to you in the scope of the template.
5 Templates can also be used for some special actions like creating a new ticket
6 as part of the execution of a scrip.
8 Each template is split into two sections: a block of headers and a body. These
9 sections are separated by a blank line. Blank lines are not allowed before
10 the headers, but can be included in the body as needed after the headers
13 Templates are processed by the L<Text::Template> module. This module
14 allows you to embed arbitrary Perl code into your templates. Text wrapped
15 in curly braces, C<{...}> is interpreted as Perl. See L<Text::Template>
20 Your template may specify arbitrary email headers. Each header is a name, a
21 colon, then a value. So, for example, to specify a subject, you can use:
23 Subject: Thanks for your bug report.
25 =head3 Special Headers
29 =item RT-Attach-Message: yes
31 This special header tells RT that any attachments that were added in the
32 original message should also be included in the email notification going out.
34 =item Content-Type: text/html
36 The special header "Content-Type: text/html" tells RT that the template should
37 be parsed as HTML. RT will automatically make the outgoing message multipart.
38 That way, recipients who can read only plaintext email will receive something
39 readable, while users with clients which can display HTML will receive the full
40 experience. Please be aware that HTML support in mail clients varies greatly,
41 much more so than different web browsers.
43 Starting in RT 4.2, HTML templates are included along with plain text templates
44 for the standard RT notifications.
50 Templates have a Type which dictates the level of code execution allowed.
52 Templates of type C<Perl> are evaluated using L<Text::Template>
53 which allows arbitrary code execution. Only users with the global
54 C<ExecuteCode> privilege may write templates of type C<Perl>. Prior to
55 RT 4.0, this was the only type of Template available.
57 Templates of type C<Simple> permit only simple variable interpolation.
58 No special privilege beyond C<ModifyTemplate> is needed to write C<Simple>
61 For both types of templates, text between curly braces C<{ ... }> is
62 interpolated. For C<Perl> templates, this text can be any code (see
63 L<Text::Template/Details>). For C<Simple> templates, only simple variables
64 are permitted; for example C<{ $TicketSubject }>.
70 The variables that your templates may use include:
76 The transaction object.
80 The value of the "rtname" config variable.
84 The ticket object. This is only set during a ticket transaction.
88 This is not an object, but the name of the first requestor on the ticket.
89 If this is not what you need, inspect C<< $Ticket->Requestors >>.
93 A localization function. See L<Locale::Maketext>.
97 The C<$Transaction> and C<$Ticket> objects are particularly useful. For
98 example, here are some values you can get from each:
100 $Ticket->Status # Current status
101 $Ticket->Owner # Current owner
102 $Ticket->FirstCustomFieldValue('CustomFieldName') # CF value
103 $Ticket->DueAsString # Current due date as a string
104 $Ticket->DueObj # Due as an RT::Date object
105 $Ticket->QueueObj # Queue object for this ticket
107 $Transaction->Type # Type of transaction
108 $Transaction->OldValue # Previous value, if type is Set
109 $Transaction->NewValue # New value, if type is Set
110 $Transaction->CreatorObj->EmailAddress # Email address of trans creator
112 You can see the methods available in the L<RT::Ticket> and L<RT::Transaction>
115 =head3 Selected Simple template variables
117 Since method calls are not allowed in simple templates, many common
118 method results have been placed into scalar variables for the template's
129 =item $TicketQueueName
131 =item $TicketOwnerName
133 =item $TicketOwnerEmailAddress
135 =item $TicketCF(Name)
137 For example, C<$TicketCFDepartment>. For CFs with more complicated
138 names, all non-word characters (anything that is not letters, numbers,
139 or underscores) are stripped to determine the appropriate variable name.
141 =item $TransactionType
143 =item $TransactionField
145 =item $TransactionOldValue
147 =item $TransactionNewValue
149 =item $TransactionData
151 =item $TransactionContent
153 =item $TransactionDescription
155 =item $TransactionBriefDescription
157 =item $TransactionCF(Name)
159 For example, C<$TransactionCFLocation>.
163 =head2 Templates Provided with RT
165 RT comes with a set of templates for the default notifications. As you start to
166 customize your templates, these templates are a good place to look for
167 examples. As you customize, it can be helpful to create new templates and
168 update your scrips to reference your new templates. This leaves the original RT
169 templates in place for easy reference.
171 Starting in RT 4.2, each template has a plain text version and an HTML
172 version. For example, the "Correspondence" template is the plain text version
173 of the default template for correspondence (replies) and the "Correspondence in
174 HTML" template is the same template formatted in HTML. The 4.2 upgrade provides
175 a C<switch-templates-to> script to switch all default templates from plain text
176 to HTML or the reverse. See the L<UPGRADING-4.2> notes for details.