[Templates] pre-compiling templates

darren chamberlain dlc@users.sourceforge.net
Mon, 13 Jan 2003 09:44:55 -0500


Hi allan,

* allan <lambretta@inet.uni2.dk> [2003-01-12 11:39]:
> i guess its in the manual or somewhere in the gzipped mailing list...

There is no explicit "How to precompile" section, but there are hints
scattered around.  See COMPILE_EXT, which your example shows that
you've found, and COMPILE_DIR, which is the missing piece.

> from the command line with tpage or is it possible via a browser?

It is possible from anywhere you can invoke TT.

> i had hoped that when hitting a cgi-page from a browser the first time
> it would write a compiled version of the template and then use that on
> any subsequent request [untill the original template changed
> timestamp]
> 
> the following is from a normal CGI, number 1 works as expected with no
> pre-compiling; number 2 produces an empty screen and nothing in my
> error log.

The second:

> my $template = Template->new({
> 	INCLUDE_PATH  => "$websrc/" . APACHE_ADMIN_LIB,
> 	PRE_PROCESS   => 'config',
> 	COMPILE_EXT => '.ttc', # compile extension in same dir
> });

is trying to write the compiled templates to the same directory as they
are found in.  If you also/instead set COMPILE_DIR, you can force TT to
put the compiled versions somswhere else:


my $template = Template->new({
	INCLUDE_PATH  => "$websrc/" . APACHE_ADMIN_LIB,
	PRE_PROCESS   => 'config',
	COMPILE_EXT => '.ttc', # compile extension in same dir
	COMPILE_DIR => '/tmp',
});

This will put your templates in $COMPILE_DIR/path/to/the/original; i.e.,
the template /foo/bar/baz.tt2 will go into /tmp/foo/bar/baz.tt2.

(darren)

-- 
God, to me, it seems, is a verb, not a noun, proper or improper.
    -- R. Buckminster Fuller