I am running a script that generates my pages dynamically using HTML::Template and CGI. My website has over 50 static HTML pages right now and I need to generate them dynamically. Here is the code:
#!C:/Perl/bin/perl.exe -wT
use CGI;
use HTML::Template;
use strict;
my $query = new CGI;
my $content = $query->param( "content" );
$ENV{DOCUMENT_ROOT} = "C:/Program Files/Apache Software Foundation/Apache2.2";
my $template_file = $ENV{DOCUMENT_ROOT}."/templates/main.tmpl";
unless ( $content ) {
print_index();
}
sub print_index {
my $maincontent_file_index = $ENV{DOCUMENT_ROOT}."/templates/content/index/maincontent.txt";
my $footercontent_index = $ENV{DOCUMENT_ROOT}."/templates/content/index/indexfootercontent.txt";
my $dropdown = $ENV{DOCUMENT_ROOT}."/templates/content/dropmenu.txt";
my $index_tmpl = $ENV{DOCUMENT_ROOT}."/templates/index.tmpl";
my @data1;
my @data2;
my @data3;
my $tmpl = new HTML::Template( filename => $index_tmpl );
my @content = [ content => @data1 ];
my @footer = [ footer => @data2 ];
my @dropdown = [ dropdown => @data3 ];
open(FILE,$maincontent_file_index) || die ("Could not open file:" .$!);
@data1 = <FILE>;
close (FILE);
open(FILE,$footercontent_index) || die ("Could not open file:" .$!);
@data2 = <FILE>;
close (FILE);
open(FILE,$dropdown) || die ("Could not open file:" .$!);
@data3 = <FILE>;
close (FILE);
$tmpl->param ( content => @content,
footer => @footer,
dropmenu => @dropdown );
print "Content-type: text/html\n\n";
print $tmpl->output;
exit;
}
What it's supposed to do is open the text files and put their contents in to a TMPL_VAR or whatever need be. In this case, this is the home page, so it basically has a footer, the main content, and a drop-down menu that is impossible to edit without using this dynamic generation script. Could you please help me make it open the files, read their contents and print their contents in HTML using HTML::Template? I will be very grateful if I could have some help.
#!C:/Perl/bin/perl.exe -wT
use CGI;
use HTML::Template;
use strict;
my $query = new CGI;
my $content = $query->param( "content" );
$ENV{DOCUMENT_ROOT} = "C:/Program Files/Apache Software Foundation/Apache2.2";
my $template_file = $ENV{DOCUMENT_ROOT}."/templates/main.tmpl";
unless ( $content ) {
print_index();
}
sub print_index {
my $maincontent_file_index = $ENV{DOCUMENT_ROOT}."/templates/content/index/maincontent.txt";
my $footercontent_index = $ENV{DOCUMENT_ROOT}."/templates/content/index/indexfootercontent.txt";
my $dropdown = $ENV{DOCUMENT_ROOT}."/templates/content/dropmenu.txt";
my $index_tmpl = $ENV{DOCUMENT_ROOT}."/templates/index.tmpl";
my @data1;
my @data2;
my @data3;
my $tmpl = new HTML::Template( filename => $index_tmpl );
my @content = [ content => @data1 ];
my @footer = [ footer => @data2 ];
my @dropdown = [ dropdown => @data3 ];
open(FILE,$maincontent_file_index) || die ("Could not open file:" .$!);
@data1 = <FILE>;
close (FILE);
open(FILE,$footercontent_index) || die ("Could not open file:" .$!);
@data2 = <FILE>;
close (FILE);
open(FILE,$dropdown) || die ("Could not open file:" .$!);
@data3 = <FILE>;
close (FILE);
$tmpl->param ( content => @content,
footer => @footer,
dropmenu => @dropdown );
print "Content-type: text/html\n\n";
print $tmpl->output;
exit;
}
What it's supposed to do is open the text files and put their contents in to a TMPL_VAR or whatever need be. In this case, this is the home page, so it basically has a footer, the main content, and a drop-down menu that is impossible to edit without using this dynamic generation script. Could you please help me make it open the files, read their contents and print their contents in HTML using HTML::Template? I will be very grateful if I could have some help.