LPM: Text::Template and server-side includes in HTML files

Joe Hourcle oneiros at dcr.net
Thu Aug 31 08:39:18 CDT 2000

On Wed, 30 Aug 2000, Frank Price wrote:

> On Wed, Aug 30, 2000 at 05:34:41PM -0400, Gregg Casillo wrote:
> > I've come up against this problem more and more recently: I use
> > Text::Template to plug some data into an HTML page and spit it out to
> > the browser. However, the static HTML page has several server-side
> > includes (and sometimes these includes have more includes nested within
> > them) in it which Text::Template does not seem to handle.
> > 
> > Does anyone who uses Text::Template know of a way around this without
> > getting rid of the server-side includes?
> I thought CGI-generated pages couldn't use SSIs as such b/c the page
> went directly to the browser without the httpd ever seeing it.  So the
> web server never has a chance to expand the include.  Or at least
> that's the rationale I dreamed up when I could never make it work.

You are correct.  SSIs only work when the server reads the page, not when
the page is being generated by a CGI.

> I've done my own cheap SSIs like this (from within the perl script):
>    open(SSI, "header.ssi");
>    print $_ while (<SSI>);
>    close SSI;
> Would be interested to know if you find a better way...

Well, almost the same, but to avoid the while loop, you can either do:

	open (SSI, '< header.ssi');
	print <SSI>;
	close SSI;

or, as I think ModPerl allows you to keep persistant data:

	$/ = undef;

	my $header = &read_file('header.ssi');
	my $footer = &read_file('footer.ssi');
	my $blah   = &read_file('blah.ssi');

	sub read_file {
		open (TEMP, "< $ARGV[0]");
		my $temp = <TEMP>;
		close (TEMP);
		return $temp;

and then you can just print $header from Text::Template

Joe Hourcle

More information about the Lexington-pm mailing list