[Templates] INCLUDE with http/ftp?

Craig Barratt craig@arraycomm.com
Fri, 18 May 2001 17:06:59 -0700

> i am trying to include a txt file into a webpage created by tt2.  i am
> trying to use the INCLUDES directive, but the file i'm trying to
> ICLUDE the file using a URL (http:// or ftp://). i can use an absolute
> path if there is no other way, but it will complicate things a lot.
> i was wondering if there is anyway to fetch a file using http:// or
> ftp:// and include that?

Here's one way.  Set the LOAD_PERL option:

    use Template;

    my $template = Template->new({
    $template->process("example.tt", { stdout => *STDOUT })
				 || die $template->error();

and then use LWP::UserAgent and HTTP::Request:

	USE ua = LWP.UserAgent;
	ua.proxy("http", "http://your_proxy/");
	USE req = HTTP.Request("GET", "http://www.cpan.org");

For FTP use Net::FTP:

	USE ftp = Net.FTP("ftp.cpan.org");
	x = ftp.login("anonymous", "me@here.there");
	x = ftp.cwd("/");
	x = ftp.get("welcome.msg", stdout);
	x = ftp.quit;

Normally ftp.get would write the file into the current directory.
Instead we pass stdout as a second argument so that it is written
to stdout.  We set stdout to STDOUT in the variables we pass to