Apache-Template
view release on metacpan or search on metacpan
lib/Apache/Template.pm view on Meta::CPAN
TT2ContentType text/xml
=item TT2Params
Allows you to specify which parameters you want defined as template
variables. Current permitted values are 'uri', 'env' (hash of
environment variables), 'params' (hash of CGI parameters), 'pnotes'
(the request pnotes hash), 'cookies' (hash of cookies), 'uploads' (a
list of Apache::Upload instances), 'request' (the Apache::Request
object) or 'all' (all of the above).
TT2Params uri env params uploads request
When set, these values can then be accessed from within any
template processed:
The URI is [% uri %]
Server name is [% env.SERVER_NAME %]
CGI params are:
<table>
[% FOREACH key = params.keys %]
<tr>
<td>[% key %]</td> <td>[% params.$key %]</td>
</tr>
[% END %]
</table>
=item TT2ServiceModule
The modules have been designed in such a way as to make it easy to
subclass the Template::Service::Apache module to create your own
custom services.
For example, the regular service module does a simple 1:1 mapping of
URI to template using the request filename provided by Apache, but
you might want to implement an alternative scheme. You might prefer,
for example, to map multiple URIs to the same template file, but to
set some different template variables along the way.
To do this, you can subclass Template::Service::Apache and redefine
the appropriate methods. The template() method performs the task of
mapping URIs to templates and the params() method sets up the template
variable parameters. Or if you need to modify the HTTP headers, then
headers() is the one for you.
The TT2ServiceModule option can be set to indicate the name of your
custom service module. The following trivial example shows how you
might subclass Template::Service::Apache to add an additional parameter,
in this case as the template variable 'message'.
<perl>
package My::Service::Module;
use base qw( Template::Service::Apache );
sub params {
my $self = shift;
my $params = $self->SUPER::params(@_);
$params->{ message } = 'Hello World';
return $params;
}
</perl>
PerlModule Apache::Template
TT2ServiceModule My::Service::Module
=back
=head1 CONFIGURATION MERGING
The Apache::Template module creates a separate service for each
virtual server. Each virtual server can have its own configuration.
Any globally defined options will be merged with any server-specific
ones.
The following examples illustrates two separate virtual servers being
configured in one Apache configuration file.
PerlModule Apache::Template
TT2IncludePath /usr/local/tt2/templates
TT2Params request params
TT2Wrapper html/page
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
ServerName shoveit
SetHandler perl-script
PerlHandler Apache::Template
TT2Wrapper layout_a
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName kickflip
SetHandler perl-script
PerlHandler Apache::Template
TT2Wrapper layout_b
</VirtualHost>
In this example, the C<shoveit> virtual host will be configured as if written:
PerlModule Apache::Template
TT2IncludePath /usr/local/tt2/templates
TT2Params request params
TT2Wrapper html/page
TT2Wrapper layout_a
The second C<TTWrapper> option (C<layout_a>) is added to the shared
configuration block.
The C<kickflip> virtual host will be configured as if written:
PerlModule Apache::Template
TT2IncludePath /usr/local/tt2/templates
TT2Params request params
TT2Wrapper html/page
TT2Wrapper layout_b
( run in 1.774 second using v1.01-cache-2.11-cpan-2398b32b56e )