.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.13)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.ie \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.el \{\
. de IX
..
.\}
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "Template 3"
.TH Template 3 "2007-01-29" "perl v5.12.0" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
HTML::Template \- Perl module to use HTML Templates from CGI scripts
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
First you make a template \- this is just a normal \s-1HTML\s0 file with a few
extra tags, the simplest being <\s-1TMPL_VAR\s0>
.PP
For example, test.tmpl:
.PP
.Vb 8
\&
\&
Test Template
\&
\& My Home Directory is
\&
\& My Path is set to
\&
\&
.Ve
.PP
Now create a small \s-1CGI\s0 program:
.PP
.Vb 2
\& #!/usr/bin/perl \-w
\& use HTML::Template;
\&
\& # open the html template
\& my $template = HTML::Template\->new(filename => \*(Aqtest.tmpl\*(Aq);
\&
\& # fill in some parameters
\& $template\->param(HOME => $ENV{HOME});
\& $template\->param(PATH => $ENV{PATH});
\&
\& # send the obligatory Content\-Type and print the template output
\& print "Content\-Type: text/html\en\en", $template\->output;
.Ve
.PP
If all is well in the universe this should show something like this in
your browser when visiting the \s-1CGI:\s0
.PP
.Vb 2
\& My Home Directory is /home/some/directory
\& My Path is set to /bin;/usr/bin
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This module attempts to make using \s-1HTML\s0 templates simple and natural.
It extends standard \s-1HTML\s0 with a few new HTML-esque tags \- <\s-1TMPL_VAR\s0>,
<\s-1TMPL_LOOP\s0>, <\s-1TMPL_INCLUDE\s0>, <\s-1TMPL_IF\s0>, <\s-1TMPL_ELSE\s0> and <\s-1TMPL_UNLESS\s0>.
The file written with \s-1HTML\s0 and these new tags is called a template.
It is usually saved separate from your script \- possibly even created
by someone else! Using this module you fill in the values for the
variables, loops and branches declared in the template. This allows
you to separate design \- the \s-1HTML\s0 \- from the data, which you generate
in the Perl script.
.PP
This module is licensed under the \s-1GPL\s0. See the \s-1LICENSE\s0 section
below for more details.
.SH "TUTORIAL"
.IX Header "TUTORIAL"
If you're new to HTML::Template, I suggest you start with the
introductory article available on the HTML::Template website:
.PP
.Vb 1
\& http://html\-template.sourceforge.net
.Ve
.SH "MOTIVATION"
.IX Header "MOTIVATION"
It is true that there are a number of packages out there to do \s-1HTML\s0
templates. On the one hand you have things like HTML::Embperl which
allows you freely mix Perl with \s-1HTML\s0. On the other hand lie
home-grown variable substitution solutions. Hopefully the module can
find a place between the two.
.PP
One advantage of this module over a full HTML::Embperl\-esque solution
is that it enforces an important divide \- design and programming. By
limiting the programmer to just using simple variables and loops in
the \s-1HTML\s0, the template remains accessible to designers and other
non-perl people. The use of HTML-esque syntax goes further to make
the format understandable to others. In the future this similarity
could be used to extend existing \s-1HTML\s0 editors/analyzers to support
HTML::Template.
.PP
An advantage of this module over home-grown tag-replacement schemes is
the support for loops. In my work I am often called on to produce
tables of data in html. Producing them using simplistic \s-1HTML\s0
templates results in CGIs containing lots of \s-1HTML\s0 since the \s-1HTML\s0
itself cannot represent loops. The introduction of loop statements in
the \s-1HTML\s0 simplifies this situation considerably. The designer can
layout a single row and the programmer can fill it in as many times as
necessary \- all they must agree on is the parameter names.
.PP
For all that, I think the best thing about this module is that it does
just one thing and it does it quickly and carefully. It doesn't try
to replace Perl and \s-1HTML\s0, it just augments them to interact a little
better. And it's pretty fast.
.SH "THE TAGS"
.IX Header "THE TAGS"
.SS "\s-1TMPL_VAR\s0"
.IX Subsection "TMPL_VAR"
.Vb 1
\&
.Ve
.PP
The <\s-1TMPL_VAR\s0> tag is very simple. For each <\s-1TMPL_VAR\s0> tag in the
template you call \f(CW$template\fR\->param(\s-1PARAMETER_NAME\s0 => \*(L"\s-1VALUE\s0\*(R"). When
the template is output the <\s-1TMPL_VAR\s0> is replaced with the \s-1VALUE\s0 text
you specified. If you don't set a parameter it just gets skipped in
the output.
.PP
Optionally you can use the \*(L"ESCAPE=HTML\*(R" option in the tag to indicate
that you want the value to be HTML-escaped before being returned from
output (the old ESCAPE=1 syntax is still supported). This means that
the ", <, >, and & characters get translated into ", <, >
and & respectively. This is useful when you want to use a
\&\s-1TMPL_VAR\s0 in a context where those characters would cause trouble.
Example:
.PP
.Vb 1
\& ">
.Ve
.PP
If you called \f(CW\*(C`param()\*(C'\fR with a value like sam"my you'll get in trouble
with \s-1HTML\s0's idea of a double-quote. On the other hand, if you use
ESCAPE=HTML, like this:
.PP
.Vb 1
\& ">
.Ve
.PP
You'll get what you wanted no matter what value happens to be passed in for
param. You can also write ESCAPE=\*(L"\s-1HTML\s0\*(R", ESCAPE='\s-1HTML\s0' and ESCAPE='1'.
.PP
\&\*(L"ESCAPE=0\*(R" and \*(L"ESCAPE=NONE\*(R" turn off escaping, which is the default
behavior.
.PP
There is also the \*(L"ESCAPE=URL\*(R" option which may be used for VARs that
populate a \s-1URL\s0. It will do \s-1URL\s0 escaping, like replacing ' ' with '+'
and '/' with '%2F'.
.PP
There is also the \*(L"ESCAPE=JS\*(R" option which may be used for VARs that
need to be placed within a Javascript string. All \en, \er, ' and " characters
are escaped.
.PP
You can assign a default value to a variable with the \s-1DEFAULT\s0
attribute. For example, this will output \*(L"the devil gave me a taco\*(R"
if the \*(L"who\*(R" variable is not set.
.PP
.Vb 1
\& The gave me a taco.
.Ve
.SS "\s-1TMPL_LOOP\s0"
.IX Subsection "TMPL_LOOP"
.Vb 1
\& ...
.Ve
.PP
The <\s-1TMPL_LOOP\s0> tag is a bit more complicated than <\s-1TMPL_VAR\s0>. The
<\s-1TMPL_LOOP\s0> tag allows you to delimit a section of text and give it a
name. Inside this named loop you place <\s-1TMPL_VAR\s0>s. Now you pass to
\&\f(CW\*(C`param()\*(C'\fR a list (an array ref) of parameter assignments (hash refs) for
this loop. The loop iterates over the list and produces output from
the text block for each pass. Unset parameters are skipped. Here's
an example:
.PP
.Vb 1
\& In the template:
\&
\&
\& Name:
\& Job:
\&
\&
\&
\& In the script:
\&
\& $template\->param(EMPLOYEE_INFO => [
\& { name => \*(AqSam\*(Aq, job => \*(Aqprogrammer\*(Aq },
\& { name => \*(AqSteve\*(Aq, job => \*(Aqsoda jerk\*(Aq },
\& ]
\& );
\& print $template\->output();
\&
\&
\& The output in a browser:
\&
\& Name: Sam
\& Job: programmer
\&
\& Name: Steve
\& Job: soda jerk
.Ve
.PP
As you can see above the <\s-1TMPL_LOOP\s0> takes a list of variable
assignments and then iterates over the loop body producing output.
.PP
Often you'll want to generate a <\s-1TMPL_LOOP\s0>'s contents
programmatically. Here's an example of how this can be done (many
other ways are possible!):
.PP
.Vb 3
\& # a couple of arrays of data to put in a loop:
\& my @words = qw(I Am Cool);
\& my @numbers = qw(1 2 3);
\&
\& my @loop_data = (); # initialize an array to hold your loop
\&
\& while (@words and @numbers) {
\& my %row_data; # get a fresh hash for the row data
\&
\& # fill in this row
\& $row_data{WORD} = shift @words;
\& $row_data{NUMBER} = shift @numbers;
\&
\& # the crucial step \- push a reference to this row into the loop!
\& push(@loop_data, \e%row_data);
\& }
\&
\& # finally, assign the loop data to the loop param, again with a
\& # reference:
\& $template\->param(THIS_LOOP => \e@loop_data);
.Ve
.PP
The above example would work with a template like:
.PP
.Vb 4
\&
\& Word:
\& Number:
\&
.Ve
.PP
It would produce output like:
.PP
.Vb 2
\& Word: I
\& Number: 1
\&
\& Word: Am
\& Number: 2
\&
\& Word: Cool
\& Number: 3
.Ve
.PP
<\s-1TMPL_LOOP\s0>s within <\s-1TMPL_LOOP\s0>s are fine and work as you would
expect. If the syntax for the \f(CW\*(C`param()\*(C'\fR call has you stumped, here's an
example of a param call with one nested loop:
.PP
.Vb 9
\& $template\->param(LOOP => [
\& { name => \*(AqBobby\*(Aq,
\& nicknames => [
\& { name => \*(Aqthe big bad wolf\*(Aq },
\& { name => \*(AqHe\-Man\*(Aq },
\& ],
\& },
\& ],
\& );
.Ve
.PP
Basically, each <\s-1TMPL_LOOP\s0> gets an array reference. Inside the array
are any number of hash references. These hashes contain the
name=>value pairs for a single pass over the loop template.
.PP
Inside a <\s-1TMPL_LOOP\s0>, the only variables that are usable are the ones
from the <\s-1TMPL_LOOP\s0>. The variables in the outer blocks are not
visible within a template loop. For the computer-science geeks among
you, a <\s-1TMPL_LOOP\s0> introduces a new scope much like a perl subroutine
call. If you want your variables to be global you can use
\&'global_vars' option to \fInew()\fR described below.
.SS "\s-1TMPL_INCLUDE\s0"
.IX Subsection "TMPL_INCLUDE"
.Vb 1
\&
.Ve
.PP
This tag includes a template directly into the current template at the
point where the tag is found. The included template contents are used
exactly as if its contents were physically included in the master
template.
.PP
The file specified can be an absolute path (beginning with a '/' under
Unix, for example). If it isn't absolute, the path to the enclosing
file is tried first. After that the path in the environment variable
\&\s-1HTML_TEMPLATE_ROOT\s0 is tried, if it exists. Next, the \*(L"path\*(R" option is
consulted, first as-is and then with \s-1HTML_TEMPLATE_ROOT\s0 prepended if
available. As a final attempt, the filename is passed to \fIopen()\fR
directly. See below for more information on \s-1HTML_TEMPLATE_ROOT\s0 and
the \*(L"path\*(R" option to \fInew()\fR.
.PP
As a protection against infinitly recursive includes, an arbitary
limit of 10 levels deep is imposed. You can alter this limit with the
\&\*(L"max_includes\*(R" option. See the entry for the \*(L"max_includes\*(R" option
below for more details.
.SS "\s-1TMPL_IF\s0"
.IX Subsection "TMPL_IF"
.Vb 1
\& ...
.Ve
.PP
The <\s-1TMPL_IF\s0> tag allows you to include or not include a block of the
template based on the value of a given parameter name. If the
parameter is given a value that is true for Perl \- like '1' \- then the
block is included in the output. If it is not defined, or given a
false value \- like '0' \- then it is skipped. The parameters are
specified the same way as with \s-1TMPL_VAR\s0.
.PP
Example Template:
.PP
.Vb 3
\&
\& Some text that only gets displayed if BOOL is true!
\&
.Ve
.PP
Now if you call \f(CW$template\fR\->param(\s-1BOOL\s0 => 1) then the above block will
be included by output.
.PP
<\s-1TMPL_IF\s0> blocks can include any valid HTML::Template
construct \- VARs and LOOPs and other \s-1IF/ELSE\s0 blocks. Note, however,
that intersecting a <\s-1TMPL_IF\s0> and a <\s-1TMPL_LOOP\s0> is invalid.
.PP
.Vb 5
\& Not going to work:
\&
\&
\&
\&
.Ve
.PP
If the name of a \s-1TMPL_LOOP\s0 is used in a \s-1TMPL_IF\s0, the \s-1IF\s0 block will
output if the loop has at least one row. Example:
.PP
.Vb 3
\&
\& This will output if the loop is not empty.
\&
\&
\&
\& ....
\&
.Ve
.PP
\&\s-1WARNING:\s0 Much of the benefit of HTML::Template is in decoupling your
Perl and \s-1HTML\s0. If you introduce numerous cases where you have
TMPL_IFs and matching Perl \fIif()\fRs, you will create a maintenance
problem in keeping the two synchronized. I suggest you adopt the
practice of only using \s-1TMPL_IF\s0 if you can do so without requiring a
matching \fIif()\fR in your Perl code.
.SS "\s-1TMPL_ELSE\s0"
.IX Subsection "TMPL_ELSE"
.Vb 1
\& ... ...
.Ve
.PP
You can include an alternate block in your \s-1TMPL_IF\s0 block by using
\&\s-1TMPL_ELSE\s0. \s-1NOTE:\s0 You still end the block with , not
!
.PP
.Vb 1
\& Example:
\&
\&
\& Some text that is included only if BOOL is true
\&
\& Some text that is included only if BOOL is false
\&
.Ve
.SS "\s-1TMPL_UNLESS\s0"
.IX Subsection "TMPL_UNLESS"
.Vb 1
\& ...
.Ve
.PP
This tag is the opposite of <\s-1TMPL_IF\s0>. The block is output if the
\&\s-1CONTROL_PARAMETER\s0 is set false or not defined. You can use
<\s-1TMPL_ELSE\s0> with <\s-1TMPL_UNLESS\s0> just as you can with <\s-1TMPL_IF\s0>.
.PP
.Vb 1
\& Example:
\&
\&
\& Some text that is output only if BOOL is FALSE.
\&
\& Some text that is output only if BOOL is TRUE.
\&
.Ve
.PP
If the name of a \s-1TMPL_LOOP\s0 is used in a \s-1TMPL_UNLESS\s0, the \s-1UNLESS\s0 block
output if the loop has zero rows.
.PP
.Vb 3
\&
\& This will output if the loop is empty.
\&
\&
\&
\& ....
\&
.Ve
.SS "\s-1NOTES\s0"
.IX Subsection "NOTES"
HTML::Template's tags are meant to mimic normal \s-1HTML\s0 tags. However,
they are allowed to \*(L"break the rules\*(R". Something like:
.PP
.Vb 1
\&
.Ve
.PP
is not really valid \s-1HTML\s0, but it is a perfectly valid use and will
work as planned.
.PP
The \*(L"NAME=\*(R" in the tag is optional, although for extensibility's sake I
recommend using it. Example \- \*(L"<\s-1TMPL_LOOP\s0 \s-1LOOP_NAME\s0>\*(R" is acceptable.
.PP
If you're a fanatic about valid \s-1HTML\s0 and would like your templates
to conform to valid \s-1HTML\s0 syntax, you may optionally type template tags
in the form of \s-1HTML\s0 comments. This may be of use to \s-1HTML\s0 authors who
would like to validate their templates' \s-1HTML\s0 syntax prior to
HTML::Template processing, or who use DTD-savvy editing tools.
.PP
.Vb 1
\&
.Ve
.PP
In order to realize a dramatic savings in bandwidth, the standard
(non-comment) tags will be used throughout this documentation.
.SH "METHODS"
.IX Header "METHODS"
.SS "\fInew()\fP"
.IX Subsection "new()"
Call \fInew()\fR to create a new Template object:
.PP
.Vb 3
\& my $template = HTML::Template\->new( filename => \*(Aqfile.tmpl\*(Aq,
\& option => \*(Aqvalue\*(Aq
\& );
.Ve
.PP
You must call \fInew()\fR with at least one name => value pair specifying how
to access the template text. You can use \f(CW\*(C`filename => \*(Aqfile.tmpl\*(Aq\*(C'\fR
to specify a filename to be opened as the template. Alternately you can
use:
.PP
.Vb 3
\& my $t = HTML::Template\->new( scalarref => $ref_to_template_text,
\& option => \*(Aqvalue\*(Aq
\& );
.Ve
.PP
and
.PP
.Vb 3
\& my $t = HTML::Template\->new( arrayref => $ref_to_array_of_lines ,
\& option => \*(Aqvalue\*(Aq
\& );
.Ve
.PP
These initialize the template from in-memory resources. In almost
every case you'll want to use the filename parameter. If you're
worried about all the disk access from reading a template file just
use mod_perl and the cache option detailed below.
.PP
You can also read the template from an already opened filehandle,
either traditionally as a glob or as a FileHandle:
.PP
.Vb 1
\& my $t = HTML::Template\->new( filehandle => *FH, option => \*(Aqvalue\*(Aq);
.Ve
.PP
The four \fInew()\fR calling methods can also be accessed as below, if you
prefer.
.PP
.Vb 1
\& my $t = HTML::Template\->new_file(\*(Aqfile.tmpl\*(Aq, option => \*(Aqvalue\*(Aq);
\&
\& my $t = HTML::Template\->new_scalar_ref($ref_to_template_text,
\& option => \*(Aqvalue\*(Aq);
\&
\& my $t = HTML::Template\->new_array_ref($ref_to_array_of_lines,
\& option => \*(Aqvalue\*(Aq);
\&
\& my $t = HTML::Template\->new_filehandle($fh,
\& option => \*(Aqvalue\*(Aq);
.Ve
.PP
And as a final option, for those that might prefer it, you can call new as:
.PP
.Vb 2
\& my $t = HTML::Template\->new(type => \*(Aqfilename\*(Aq,
\& source => \*(Aqfile.tmpl\*(Aq);
.Ve
.PP
Which works for all three of the source types.
.PP
If the environment variable \s-1HTML_TEMPLATE_ROOT\s0 is set and your
filename doesn't begin with /, then the path will be relative to the
value of \f(CW$HTML_TEMPLATE_ROOT\fR. Example \- if the environment variable
\&\s-1HTML_TEMPLATE_ROOT\s0 is set to \*(L"/home/sam\*(R" and I call
HTML::Template\->\fInew()\fR with filename set to \*(L"sam.tmpl\*(R", the
HTML::Template will try to open \*(L"/home/sam/sam.tmpl\*(R" to access the
template file. You can also affect the search path for files with the
\&\*(L"path\*(R" option to \fInew()\fR \- see below for more information.
.PP
You can modify the Template object's behavior with \fInew()\fR. The options
are available:
.IP "Error Detection Options" 4
.IX Item "Error Detection Options"
.RS 4
.PD 0
.IP "\(bu" 4
.PD
die_on_bad_params \- if set to 0 the module will let you call
\&\f(CW$template\fR\->param(param_name => 'value') even if 'param_name' doesn't
exist in the template body. Defaults to 1.
.IP "\(bu" 4
force_untaint \- if set to 1 the module will not allow you to set
unescaped parameters with tainted values. If set to 2 you will have
to untaint all parameters, including ones with the escape attribute.
This option makes sure you untaint everything so you don't accidentally
introduce e.g. cross-site-scripting (\s-1CSS\s0) vulnerabilities. Requires
taint mode. Defaults to 0.
.IP "\(bu" 4
strict \- if set to 0 the module will allow things that look like they
might be TMPL_* tags to get by without dieing. Example:
.Sp
.Vb 1
\&
.Ve
.Sp
Would normally cause an error, but if you call new with strict => 0,
HTML::Template will ignore it. Defaults to 1.
.IP "\(bu" 4
vanguard_compatibility_mode \- if set to 1 the module will expect to
see <\s-1TMPL_VAR\s0>s that look like \f(CW%NAME\fR% in addition to the standard
syntax. Also sets die_on_bad_params => 0. If you're not at Vanguard
Media trying to use an old format template don't worry about this one.
Defaults to 0.
.RE
.RS 4
.RE
.IP "Caching Options" 4
.IX Item "Caching Options"
.RS 4
.PD 0
.IP "\(bu" 4
.PD
cache \- if set to 1 the module will cache in memory the parsed
templates based on the filename parameter and modification date of the
file. This only applies to templates opened with the filename
parameter specified, not scalarref or arrayref templates. Caching
also looks at the modification times of any files included using
<\s-1TMPL_INCLUDE\s0> tags, but again, only if the template is opened with
filename parameter.
.Sp
This is mainly of use in a persistent environment like
Apache/mod_perl. It has absolutely no benefit in a normal \s-1CGI\s0
environment since the script is unloaded from memory after every
request. For a cache that does work for normal CGIs see the
\&'shared_cache' option below.
.Sp
Note that different \fInew()\fR parameter settings do not cause a cache
refresh, only a change in the modification time of the template will
trigger a cache refresh. For most usages this is fine. My simplistic
testing shows that using cache yields a 90% performance increase under
mod_perl. Cache defaults to 0.
.IP "\(bu" 4
shared_cache \- if set to 1 the module will store its cache in shared
memory using the IPC::SharedCache module (available from \s-1CPAN\s0). The
effect of this will be to maintain a single shared copy of each parsed
template for all instances of HTML::Template to use. This can be a
significant reduction in memory usage in a multiple server
environment. As an example, on one of our systems we use 4MB of
template cache and maintain 25 httpd processes \- shared_cache results
in saving almost 100MB! Of course, some reduction in speed versus
normal caching is to be expected. Another difference between normal
caching and shared_cache is that shared_cache will work in a \s-1CGI\s0
environment \- normal caching is only useful in a persistent
environment like Apache/mod_perl.
.Sp
By default HTML::Template uses the \s-1IPC\s0 key '\s-1TMPL\s0' as a shared root
segment (0x4c504d54 in hex), but this can be changed by setting the
\&'ipc_key' \fInew()\fR parameter to another 4\-character or integer key.
Other options can be used to affect the shared memory cache correspond
to IPC::SharedCache options \- ipc_mode, ipc_segment_size and
ipc_max_size. See IPC::SharedCache for a description of how these
work \- in most cases you shouldn't need to change them from the
defaults.
.Sp
For more information about the shared memory cache system used by
HTML::Template see IPC::SharedCache.
.IP "\(bu" 4
double_cache \- if set to 1 the module will use a combination of
shared_cache and normal cache mode for the best possible caching. Of
course, it also uses the most memory of all the cache modes. All the
same ipc_* options that work with shared_cache apply to double_cache
as well. By default double_cache is off.
.IP "\(bu" 4
blind_cache \- if set to 1 the module behaves exactly as with normal
caching but does not check to see if the file has changed on each
request. This option should be used with caution, but could be of use
on high-load servers. My tests show blind_cache performing only 1 to
2 percent faster than cache under mod_perl.
.Sp
\&\s-1NOTE:\s0 Combining this option with shared_cache can result in stale
templates stuck permanently in shared memory!
.IP "\(bu" 4
file_cache \- if set to 1 the module will store its cache in a file
using the Storable module. It uses no additional memory, and my
simplistic testing shows that it yields a 50% performance advantage.
Like shared_cache, it will work in a \s-1CGI\s0 environment. Default is 0.
.Sp
If you set this option you must set the \*(L"file_cache_dir\*(R" option. See
below for details.
.Sp
\&\s-1NOTE:\s0 Storable using \fIflock()\fR to ensure safe access to cache files.
Using file_cache on a system or filesystem (\s-1NFS\s0) without \fIflock()\fR
support is dangerous.
.IP "\(bu" 4
file_cache_dir \- sets the directory where the module will store the
cache files if file_cache is enabled. Your script will need write
permissions to this directory. You'll also need to make sure the
sufficient space is available to store the cache files.
.IP "\(bu" 4
file_cache_dir_mode \- sets the file mode for newly created file_cache
directories and subdirectories. Defaults to 0700 for security but
this may be inconvenient if you do not have access to the account
running the webserver.
.IP "\(bu" 4
double_file_cache \- if set to 1 the module will use a combination of
file_cache and normal cache mode for the best possible caching. The
file_cache_* options that work with file_cache apply to double_file_cache
as well. By default double_file_cache is 0.
.RE
.RS 4
.RE
.IP "Filesystem Options" 4
.IX Item "Filesystem Options"
.RS 4
.PD 0
.IP "\(bu" 4
.PD
path \- you can set this variable with a list of paths to search for
files specified with the \*(L"filename\*(R" option to \fInew()\fR and for files
included with the <\s-1TMPL_INCLUDE\s0> tag. This list is only consulted
when the filename is relative. The \s-1HTML_TEMPLATE_ROOT\s0 environment
variable is always tried first if it exists. Also, if
\&\s-1HTML_TEMPLATE_ROOT\s0 is set then an attempt will be made to prepend
\&\s-1HTML_TEMPLATE_ROOT\s0 onto paths in the path array. In the case of a
<\s-1TMPL_INCLUDE\s0> file, the path to the including file is also tried
before path is consulted.
.Sp
Example:
.Sp
.Vb 5
\& my $template = HTML::Template\->new( filename => \*(Aqfile.tmpl\*(Aq,
\& path => [ \*(Aq/path/to/templates\*(Aq,
\& \*(Aq/alternate/path\*(Aq
\& ]
\& );
.Ve
.Sp
\&\s-1NOTE:\s0 the paths in the path list must be expressed as \s-1UNIX\s0 paths,
separated by the forward-slash character ('/').
.IP "\(bu" 4
search_path_on_include \- if set to a true value the module will search
from the top of the array of paths specified by the path option on
every <\s-1TMPL_INCLUDE\s0> and use the first matching template found. The
normal behavior is to look only in the current directory for a
template to include. Defaults to 0.
.RE
.RS 4
.RE
.IP "Debugging Options" 4
.IX Item "Debugging Options"
.RS 4
.PD 0
.IP "\(bu" 4
.PD
debug \- if set to 1 the module will write random debugging information
to \s-1STDERR\s0. Defaults to 0.
.IP "\(bu" 4
stack_debug \- if set to 1 the module will use Data::Dumper to print
out the contents of the parse_stack to \s-1STDERR\s0. Defaults to 0.
.IP "\(bu" 4
cache_debug \- if set to 1 the module will send information on cache
loads, hits and misses to \s-1STDERR\s0. Defaults to 0.
.IP "\(bu" 4
shared_cache_debug \- if set to 1 the module will turn on the debug
option in IPC::SharedCache \- see IPC::SharedCache for
details. Defaults to 0.
.IP "\(bu" 4
memory_debug \- if set to 1 the module will send information on cache
memory usage to \s-1STDERR\s0. Requires the GTop module. Defaults to 0.
.RE
.RS 4
.RE
.IP "Miscellaneous Options" 4
.IX Item "Miscellaneous Options"
.RS 4
.PD 0
.IP "\(bu" 4
.PD
associate \- this option allows you to inherit the parameter values
from other objects. The only requirement for the other object is that
it have a \f(CW\*(C`param()\*(C'\fR method that works like HTML::Template's \f(CW\*(C`param()\*(C'\fR. A
good candidate would be a \s-1CGI\s0.pm query object. Example:
.Sp
.Vb 3
\& my $query = new CGI;
\& my $template = HTML::Template\->new(filename => \*(Aqtemplate.tmpl\*(Aq,
\& associate => $query);
.Ve
.Sp
Now, \f(CW\*(C`$template\->output()\*(C'\fR will act as though
.Sp
.Vb 1
\& $template\->param(\*(AqFormField\*(Aq, $cgi\->param(\*(AqFormField\*(Aq));
.Ve
.Sp
had been specified for each key/value pair that would be provided by
the \f(CW\*(C`$cgi\->param()\*(C'\fR method. Parameters you set directly take
precedence over associated parameters.
.Sp
You can specify multiple objects to associate by passing an anonymous
array to the associate option. They are searched for parameters in
the order they appear:
.Sp
.Vb 2
\& my $template = HTML::Template\->new(filename => \*(Aqtemplate.tmpl\*(Aq,
\& associate => [$query, $other_obj]);
.Ve
.Sp
The old \fIassociateCGI()\fR call is still supported, but should be
considered obsolete.
.Sp
\&\s-1NOTE:\s0 The parameter names are matched in a case-insensitve manner. If
you have two parameters in a \s-1CGI\s0 object like '\s-1NAME\s0' and 'Name' one
will be chosen randomly by associate. This behavior can be changed by
the following option.
.IP "\(bu" 4
case_sensitive \- setting this option to true causes HTML::Template to
treat template variable names case-sensitively. The following example
would only set one parameter without the \*(L"case_sensitive\*(R" option:
.Sp
.Vb 6
\& my $template = HTML::Template\->new(filename => \*(Aqtemplate.tmpl\*(Aq,
\& case_sensitive => 1);
\& $template\->param(
\& FieldA => \*(Aqfoo\*(Aq,
\& fIELDa => \*(Aqbar\*(Aq,
\& );
.Ve
.Sp
This option defaults to off.
.Sp
\&\s-1NOTE:\s0 with case_sensitive and loop_context_vars the special loop
variables are available in lower-case only.
.IP "\(bu" 4
loop_context_vars \- when this parameter is set to true (it is false by
default) four loop context variables are made available inside a loop:
_\|_first_\|_, _\|_last_\|_, _\|_inner_\|_, _\|_odd_\|_. They can be used with
<\s-1TMPL_IF\s0>, <\s-1TMPL_UNLESS\s0> and <\s-1TMPL_ELSE\s0> to control how a loop is
output.
.Sp
In addition to the above, a _\|_counter_\|_ var is also made available
when loop context variables are turned on.
.Sp
Example:
.Sp
.Vb 4
\&
\&
\& This only outputs on the first pass.
\&
\&
\&
\& This outputs every other pass, on the odd passes.
\&
\&
\&
\& This outputs every other pass, on the even passes.
\&
\&
\&
\& This outputs on passes that are neither first nor last.
\&
\&
\& This is pass number .
\&
\&
\& This only outputs on the last pass.
\&
\&
.Ve
.Sp
One use of this feature is to provide a \*(L"separator\*(R" similar in effect
to the perl function \fIjoin()\fR. Example:
.Sp
.Vb 4
\&
\& and
\& , .
\&
.Ve
.Sp
Would output (in a browser) something like:
.Sp
.Vb 1
\& Apples, Oranges, Brains, Toes, and Kiwi.
.Ve
.Sp
Given an appropriate \f(CW\*(C`param()\*(C'\fR call, of course. \s-1NOTE:\s0 A loop with only
a single pass will get both _\|_first_\|_ and _\|_last_\|_ set to true, but
not _\|_inner_\|_.
.IP "\(bu" 4
no_includes \- set this option to 1 to disallow the <\s-1TMPL_INCLUDE\s0> tag
in the template file. This can be used to make opening untrusted
templates \fBslightly\fR less dangerous. Defaults to 0.
.IP "\(bu" 4
max_includes \- set this variable to determine the maximum depth that
includes can reach. Set to 10 by default. Including files to a depth
greater than this value causes an error message to be displayed. Set
to 0 to disable this protection.
.IP "\(bu" 4
global_vars \- normally variables declared outside a loop are not
available inside a loop. This option makes <\s-1TMPL_VAR\s0>s like global
variables in Perl \- they have unlimited scope. This option also
affects <\s-1TMPL_IF\s0> and <\s-1TMPL_UNLESS\s0>.
.Sp
Example:
.Sp
.Vb 1
\& This is a normal variable: .
\&
\&
\& Here it is inside the loop:
\&
.Ve
.Sp
Normally this wouldn't work as expected, since <\s-1TMPL_VAR\s0 \s-1NORMAL\s0>'s
value outside the loop is not available inside the loop.
.Sp
The global_vars option also allows you to access the values of an
enclosing loop within an inner loop. For example, in this loop the
inner loop will have access to the value of \s-1OUTER_VAR\s0 in the correct
iteration:
.Sp
.Vb 7
\&
\& OUTER:
\&
\& INNER:
\& INSIDE OUT:
\&
\&
.Ve
.Sp
One side-effect of global-vars is that variables you set with \fIparam()\fR
that might otherwise be ignored when die_on_bad_params is off will
stick around. This is necessary to allow inner loops to access values
set for outer loops that don't directly use the value.
.Sp
\&\fB\s-1NOTE\s0\fR: \f(CW\*(C`global_vars\*(C'\fR is not \f(CW\*(C`global_loops\*(C'\fR (which does not exist).
That means that loops you declare at one scope are not available
inside other loops even when \f(CW\*(C`global_vars\*(C'\fR is on.
.IP "\(bu" 4
filter \- this option allows you to specify a filter for your template
files. A filter is a subroutine that will be called after
HTML::Template reads your template file but before it starts parsing
template tags.
.Sp
In the most simple usage, you simply assign a code reference to the
filter parameter. This subroutine will recieve a single argument \- a
reference to a string containing the template file text. Here is an
example that accepts templates with tags that look like \*(L"!!!ZAP_VAR
\&\s-1FOO\s0!!!\*(R" and transforms them into HTML::Template tags:
.Sp
.Vb 4
\& my $filter = sub {
\& my $text_ref = shift;
\& $$text_ref =~ s/!!!ZAP_(.*?)!!!//g;
\& };
\&
\& # open zap.tmpl using the above filter
\& my $template = HTML::Template\->new(filename => \*(Aqzap.tmpl\*(Aq,
\& filter => $filter);
.Ve
.Sp
More complicated usages are possible. You can request that your
filter receieve the template text as an array of lines rather than as
a single scalar. To do that you need to specify your filter using a
hash-ref. In this form you specify the filter using the \f(CW\*(C`sub\*(C'\fR key and
the desired argument format using the \f(CW\*(C`format\*(C'\fR key. The available
formats are \f(CW\*(C`scalar\*(C'\fR and \f(CW\*(C`array\*(C'\fR. Using the \f(CW\*(C`array\*(C'\fR format will incur
a performance penalty but may be more convenient in some situations.
.Sp
.Vb 3
\& my $template = HTML::Template\->new(filename => \*(Aqzap.tmpl\*(Aq,
\& filter => { sub => $filter,
\& format => \*(Aqarray\*(Aq });
.Ve
.Sp
You may also have multiple filters. This allows simple filters to be
combined for more elaborate functionality. To do this you specify an
array of filters. The filters are applied in the order they are
specified.
.Sp
.Vb 7
\& my $template = HTML::Template\->new(filename => \*(Aqzap.tmpl\*(Aq,
\& filter => [
\& { sub => \e&decompress,
\& format => \*(Aqscalar\*(Aq },
\& { sub => \e&remove_spaces,
\& format => \*(Aqarray\*(Aq }
\& ]);
.Ve
.Sp
The specified filters will be called for any TMPL_INCLUDEed files just
as they are for the main template file.
.IP "\(bu" 4
default_escape \- Set this parameter to \*(L"\s-1HTML\s0\*(R", \*(L"\s-1URL\s0\*(R" or \*(L"\s-1JS\s0\*(R" and
HTML::Template will apply the specified escaping to all variables
unless they declare a different escape in the template.
.RE
.RS 4
.RE
.SS "\fIparam()\fP"
.IX Subsection "param()"
\&\f(CW\*(C`param()\*(C'\fR can be called in a number of ways
.PP
1) To return a list of parameters in the template :
.PP
.Vb 1
\& my @parameter_names = $self\->param();
.Ve
.PP
2) To return the value set to a param :
.PP
.Vb 1
\& my $value = $self\->param(\*(AqPARAM\*(Aq);
.Ve
.PP
3) To set the value of a parameter :
.PP
.Vb 2
\& # For simple TMPL_VARs:
\& $self\->param(PARAM => \*(Aqvalue\*(Aq);
\&
\& # with a subroutine reference that gets called to get the value
\& # of the scalar. The sub will recieve the template object as a
\& # parameter.
\& $self\->param(PARAM => sub { return \*(Aqvalue\*(Aq });
\&
\& # And TMPL_LOOPs:
\& $self\->param(LOOP_PARAM =>
\& [
\& { PARAM => VALUE_FOR_FIRST_PASS, ... },
\& { PARAM => VALUE_FOR_SECOND_PASS, ... }
\& ...
\& ]
\& );
.Ve
.PP
4) To set the value of a a number of parameters :
.PP
.Vb 4
\& # For simple TMPL_VARs:
\& $self\->param(PARAM => \*(Aqvalue\*(Aq,
\& PARAM2 => \*(Aqvalue\*(Aq
\& );
\&
\& # And with some TMPL_LOOPs:
\& $self\->param(PARAM => \*(Aqvalue\*(Aq,
\& PARAM2 => \*(Aqvalue\*(Aq,
\& LOOP_PARAM =>
\& [
\& { PARAM => VALUE_FOR_FIRST_PASS, ... },
\& { PARAM => VALUE_FOR_SECOND_PASS, ... }
\& ...
\& ],
\& ANOTHER_LOOP_PARAM =>
\& [
\& { PARAM => VALUE_FOR_FIRST_PASS, ... },
\& { PARAM => VALUE_FOR_SECOND_PASS, ... }
\& ...
\& ]
\& );
.Ve
.PP
5) To set the value of a a number of parameters using a hash-ref :
.PP
.Vb 10
\& $self\->param(
\& {
\& PARAM => \*(Aqvalue\*(Aq,
\& PARAM2 => \*(Aqvalue\*(Aq,
\& LOOP_PARAM =>
\& [
\& { PARAM => VALUE_FOR_FIRST_PASS, ... },
\& { PARAM => VALUE_FOR_SECOND_PASS, ... }
\& ...
\& ],
\& ANOTHER_LOOP_PARAM =>
\& [
\& { PARAM => VALUE_FOR_FIRST_PASS, ... },
\& { PARAM => VALUE_FOR_SECOND_PASS, ... }
\& ...
\& ]
\& }
\& );
.Ve
.PP
An error occurs if you try to set a value that is tainted if the \*(L"force_untaint\*(R"
option is set.
.SS "\fIclear_params()\fP"
.IX Subsection "clear_params()"
Sets all the parameters to undef. Useful internally, if nowhere else!
.SS "\fIoutput()\fP"
.IX Subsection "output()"
\&\fIoutput()\fR returns the final result of the template. In most situations
you'll want to print this, like:
.PP
.Vb 1
\& print $template\->output();
.Ve
.PP
When output is called each occurrence of <\s-1TMPL_VAR\s0 NAME=name> is
replaced with the value assigned to \*(L"name\*(R" via \f(CW\*(C`param()\*(C'\fR. If a named
parameter is unset it is simply replaced with ''. <\s-1TMPL_LOOPS\s0> are
evaluated once per parameter set, accumlating output on each pass.
.PP
Calling \fIoutput()\fR is guaranteed not to change the state of the
Template object, in case you were wondering. This property is mostly
important for the internal implementation of loops.
.PP
You may optionally supply a filehandle to print to automatically as
the template is generated. This may improve performance and lower
memory consumption. Example:
.PP
.Vb 1
\& $template\->output(print_to => *STDOUT);
.Ve
.PP
The return value is undefined when using the \f(CW\*(C`print_to\*(C'\fR option.
.SS "\fIquery()\fP"
.IX Subsection "query()"
This method allow you to get information about the template structure.
It can be called in a number of ways. The simplest usage of query is
simply to check whether a parameter name exists in the template, using
the \f(CW\*(C`name\*(C'\fR option:
.PP
.Vb 4
\& if ($template\->query(name => \*(Aqfoo\*(Aq)) {
\& # do something if a varaible of any type
\& # named FOO is in the template
\& }
.Ve
.PP
This same usage returns the type of the parameter. The type is the
same as the tag minus the leading '\s-1TMPL_\s0'. So, for example, a
\&\s-1TMPL_VAR\s0 parameter returns '\s-1VAR\s0' from \f(CW\*(C`query()\*(C'\fR.
.PP
.Vb 3
\& if ($template\->query(name => \*(Aqfoo\*(Aq) eq \*(AqVAR\*(Aq) {
\& # do something if FOO exists and is a TMPL_VAR
\& }
.Ve
.PP
Note that the variables associated with TMPL_IFs and TMPL_UNLESSs will
be identified as '\s-1VAR\s0' unless they are also used in a \s-1TMPL_LOOP\s0, in
which case they will return '\s-1LOOP\s0'.
.PP
\&\f(CW\*(C`query()\*(C'\fR also allows you to get a list of parameters inside a loop
(and inside loops inside loops). Example loop:
.PP
.Vb 8
\&
\&
\&
\&
\&
\&
\&
\&
.Ve
.PP
And some query calls:
.PP
.Vb 2
\& # returns \*(AqLOOP\*(Aq
\& $type = $template\->query(name => \*(AqEXAMPLE_LOOP\*(Aq);
\&
\& # returns (\*(Aqbop\*(Aq, \*(Aqbee\*(Aq, \*(Aqexample_inner_loop\*(Aq)
\& @param_names = $template\->query(loop => \*(AqEXAMPLE_LOOP\*(Aq);
\&
\& # both return \*(AqVAR\*(Aq
\& $type = $template\->query(name => [\*(AqEXAMPLE_LOOP\*(Aq, \*(AqBEE\*(Aq]);
\& $type = $template\->query(name => [\*(AqEXAMPLE_LOOP\*(Aq, \*(AqBOP\*(Aq]);
\&
\& # and this one returns \*(AqLOOP\*(Aq
\& $type = $template\->query(name => [\*(AqEXAMPLE_LOOP\*(Aq,
\& \*(AqEXAMPLE_INNER_LOOP\*(Aq]);
\&
\& # and finally, this returns (\*(Aqinner_bee\*(Aq, \*(Aqinner_bop\*(Aq)
\& @inner_param_names = $template\->query(loop => [\*(AqEXAMPLE_LOOP\*(Aq,
\& \*(AqEXAMPLE_INNER_LOOP\*(Aq]);
\&
\& # for non existent parameter names you get undef
\& # this returns undef.
\& $type = $template\->query(name => \*(AqDWEAZLE_ZAPPA\*(Aq);
\&
\& # calling loop on a non\-loop parameter name will cause an error.
\& # this dies:
\& $type = $template\->query(loop => \*(AqDWEAZLE_ZAPPA\*(Aq);
.Ve
.PP
As you can see above the \f(CW\*(C`loop\*(C'\fR option returns a list of parameter
names and both \f(CW\*(C`name\*(C'\fR and \f(CW\*(C`loop\*(C'\fR take array refs in order to refer
to parameters inside loops. It is an error to use \f(CW\*(C`loop\*(C'\fR with a
parameter that is not a loop.
.PP
Note that all the names are returned in lowercase and the types are
uppercase.
.PP
Just like \f(CW\*(C`param()\*(C'\fR, \f(CW\*(C`query()\*(C'\fR with no arguments returns all the
parameter names in the template at the top level.
.SH "FREQUENTLY ASKED QUESTIONS"
.IX Header "FREQUENTLY ASKED QUESTIONS"
In the interest of greater understanding I've started a \s-1FAQ\s0 section of
the perldocs. Please look in here before you send me email.
.IP "1." 4
Q: Is there a place to go to discuss HTML::Template and/or get help?
.Sp
A: There's a mailing-list for discussing HTML::Template at
html\-template\-users@lists.sourceforge.net. To join:
.Sp
.Vb 1
\& http://lists.sourceforge.net/lists/listinfo/html\-template\-users
.Ve
.Sp
If you just want to get email when new releases are available you can
join the announcements mailing-list here:
.Sp
.Vb 1
\& http://lists.sourceforge.net/lists/listinfo/html\-template\-announce
.Ve
.IP "2." 4
Q: Is there a searchable archive for the mailing-list?
.Sp
A: Yes, you can find an archive of the SourceForge list here:
.Sp
.Vb 1
\& http://www.geocrawler.com/lists/3/SourceForge/23294/0/
.Ve
.Sp
For an archive of the old vm.com list, setup by Sean P. Scanlon, see:
.Sp
.Vb 1
\& http://bluedot.net/mail/archive/
.Ve
.IP "3." 4
Q: I want support for <\s-1TMPL_XXX\s0>! How about it?
.Sp
A: Maybe. I definitely encourage people to discuss their ideas for
HTML::Template on the mailing list. Please be ready to explain to me
how the new tag fits in with HTML::Template's mission to provide a
fast, lightweight system for using \s-1HTML\s0 templates.
.Sp
\&\s-1NOTE:\s0 Offering to program said addition and provide it in the form of
a patch to the most recent version of HTML::Template will definitely
have a softening effect on potential opponents!
.IP "4." 4
Q: I found a bug, can you fix it?
.Sp
A: That depends. Did you send me the \s-1VERSION\s0 of HTML::Template, a test
script and a test template? If so, then almost certainly.
.Sp
If you're feeling really adventurous, HTML::Template has a publically
available Subversion server. See below for more information in the \s-1PUBLIC\s0
\&\s-1SUBVERSION\s0 \s-1SERVER\s0 section.
.IP "5." 4
Q: <\s-1TMPL_VAR\s0>s from the main template aren't working inside a
<\s-1TMPL_LOOP\s0>! Why?
.Sp
A: This is the intended behavior. <\s-1TMPL_LOOP\s0> introduces a separate
scope for <\s-1TMPL_VAR\s0>s much like a subroutine call in Perl introduces a
separate scope for \*(L"my\*(R" variables.
.Sp
If you want your <\s-1TMPL_VAR\s0>s to be global you can set the
\&'global_vars' option when you call \fInew()\fR. See above for documentation
of the 'global_vars' \fInew()\fR option.
.IP "6." 4
Q: Why do you use /[Tt]/ instead of /t/i? It's so ugly!
.Sp
A: Simple \- the case-insensitive match switch is very inefficient.
According to _Mastering_Regular_Expressions_ from O'Reilly Press,
/[Tt]/ is faster and more space efficient than /t/i \- by as much as
double against long strings. //i essentially does a \fIlc()\fR on the
string and keeps a temporary copy in memory.
.Sp
When this changes, and it is in the 5.6 development series, I will
gladly use //i. Believe me, I realize [Tt] is hideously ugly.
.IP "7." 4
Q: How can I pre-load my templates using cache-mode and mod_perl?
.Sp
A: Add something like this to your startup.pl:
.Sp
.Vb 2
\& use HTML::Template;
\& use File::Find;
\&
\& print STDERR "Pre\-loading HTML Templates...\en";
\& find(
\& sub {
\& return unless /\e.tmpl$/;
\& HTML::Template\->new(
\& filename => "$File::Find::dir/$_",
\& cache => 1,
\& );
\& },
\& \*(Aq/path/to/templates\*(Aq,
\& \*(Aq/another/path/to/templates/\*(Aq
\& );
.Ve
.Sp
Note that you'll need to modify the \*(L"return unless\*(R" line to specify
the extension you use for your template files \- I use .tmpl, as you
can see. You'll also need to specify the path to your template files.
.Sp
One potential problem: the \*(L"/path/to/templates/\*(R" must be \s-1EXACTLY\s0 the
same path you use when you call HTML::Template\->\fInew()\fR. Otherwise the
cache won't know they're the same file and will load a new copy \-
instead getting a speed increase, you'll double your memory usage. To
find out if this is happening set cache_debug => 1 in your application
code and look for \*(L"\s-1CACHE\s0 \s-1MISS\s0\*(R" messages in the logs.
.IP "8." 4
Q: What characters are allowed in TMPL_* NAMEs?
.Sp
A: Numbers, letters, '.', '/', '+', '\-' and '_'.
.IP "9." 4
Q: How can I execute a program from inside my template?
.Sp
A: Short answer: you can't. Longer answer: you shouldn't since this
violates the fundamental concept behind HTML::Template \- that design
and code should be seperate.
.Sp
But, inevitably some people still want to do it. If that describes
you then you should take a look at
HTML::Template::Expr. Using
HTML::Template::Expr it should be easy to write a \fIrun_program()\fR
function. Then you can do awful stuff like:
.Sp
.Vb 1
\&
.Ve
.Sp
Just, please, don't tell me about it. I'm feeling guilty enough just
for writing HTML::Template::Expr in the first place.
.IP "10." 4
Q: Can I get a copy of these docs in Japanese?
.Sp
A: Yes you can. See Kawai Takanori's translation at:
.Sp
.Vb 1
\& http://member.nifty.ne.jp/hippo2000/perltips/html/template.htm
.Ve
.IP "11." 4
Q: What's the best way to create a