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 Content-Type: text/html
31 The special header "Content-Type: text/html" tells RT that the template should
32 be parsed as HTML. RT will automatically make the outgoing message multipart.
33 That way, recipients who can read only plaintext email will receive something
34 readable, while users with clients which can display HTML will receive the full
35 experience. Please be aware that HTML support in mail clients varies greatly,
36 much more so than different web browsers.
38 Starting in RT 4.2, HTML templates are included along with plain text templates
39 for the standard RT notifications.
45 Templates have a Type which dictates the level of code execution allowed.
47 Templates of type C<Perl> are evaluated using L<Text::Template>
48 which allows arbitrary code execution. Only users with the global
49 C<ExecuteCode> privilege may write templates of type C<Perl>. Prior to
50 RT 4.0, this was the only type of Template available.
52 Templates of type C<Simple> permit only simple variable interpolation.
53 No special privilege beyond C<ModifyTemplate> is needed to write C<Simple>
56 For both types of templates, text between curly braces C<{ ... }> is
57 interpolated. For C<Perl> templates, this text can be any code (see
58 L<Text::Template/Details>). For C<Simple> templates, only simple variables
59 are permitted; for example C<{ $TicketSubject }>.
65 The variables that your templates may use include:
71 The transaction object.
75 The value of the "rtname" config variable.
79 The ticket object. This is only set during a ticket transaction.
83 This is not an object, but the name of the first requestor on the ticket.
84 If this is not what you need, inspect C<< $Ticket->Requestors >>.
88 A localization function. See L<Locale::Maketext>.
92 The C<$Transaction> and C<$Ticket> objects are particularly useful. For
93 example, here are some values you can get from each:
95 $Ticket->Status # Current status
96 $Ticket->Owner # Current owner
97 $Ticket->FirstCustomFieldValue('CustomFieldName') # CF value
98 $Ticket->DueAsString # Current due date as a string
99 $Ticket->DueObj # Due as an RT::Date object
100 $Ticket->QueueObj # Queue object for this ticket
102 $Transaction->Type # Type of transaction
103 $Transaction->OldValue # Previous value, if type is Set
104 $Transaction->NewValue # New value, if type is Set
105 $Transaction->CreatorObj->EmailAddress # Email address of trans creator
107 You can see the methods available in the L<RT::Ticket> and L<RT::Transaction>
110 =head3 Selected Simple template variables
112 Since method calls are not allowed in simple templates, many common
113 method results have been placed into scalar variables for the template's
124 =item $TicketQueueName
126 =item $TicketOwnerName
128 =item $TicketOwnerEmailAddress
130 =item $TicketCF(Name)
132 For example, C<$TicketCFDepartment>. For CFs with more complicated
133 names, all non-word characters (anything that is not letters, numbers,
134 or underscores) are stripped to determine the appropriate variable name.
136 =item $TransactionType
138 =item $TransactionField
140 =item $TransactionOldValue
142 =item $TransactionNewValue
144 =item $TransactionData
146 =item $TransactionContent
148 =item $TransactionDescription
150 =item $TransactionBriefDescription
152 =item $TransactionCF(Name)
154 For example, C<$TransactionCFLocation>.
158 =head2 Templates Provided with RT
160 RT comes with a set of templates for the default notifications. As you start to
161 customize your templates, these templates are a good place to look for
162 examples. As you customize, it can be helpful to create new templates and
163 update your scrips to reference your new templates. This leaves the original RT
164 templates in place for easy reference.
166 Starting in RT 4.2, each template has a plain text version and an HTML
167 version. For example, the "Correspondence" template is the plain text version
168 of the default template for correspondence (replies) and the "Correspondence in
169 HTML" template is the same template formatted in HTML. The 4.2 upgrade provides
170 a C<switch-templates-to> script to switch all default templates from plain text
171 to HTML or the reverse. See the L<UPGRADING-4.2> notes for details.