PDA

For continued disscussion on this topic : Using a web template in cgi/perl scripts



Charisma
08-18-2000, 10:34 PM
I would like to modify the (html)look/feel of some existing cgi and perl files. However, there are many pages and instead of hard-coding everything. I want to use a template. How do I call the template from my perl and cgi files? I tried playing with the require function. It didn't seem to work.

Thank you!

gzazJim
08-19-2000, 01:20 AM
Hi Charisma, and welcome.

I have seen something like you want done, but I'll have to do some hunting for it. in the meanwhile, some code and/or a URL may be helpful to us.

Thanks and good luck!

Jim

Charisma
08-21-2000, 11:47 PM
Thank you! Here is the url.I want to change the look/feel of these pages:

http://support2.coppermountain.com/cgi-bin/ubb/ultimate.cgi

It's a forum just like this one! Most of the menus/footers are hard-coded throughout. This is all in the prototype stage.

Thanks again,
Charisma

big_wreck
08-22-2000, 04:40 AM
I have not actually done this but could you not read a flat file of HTML code and then simply print the variable out in the cgi that calls it ?

eg:

$template = 'some/path/to/filename';
open (TEMP,"<$template");
$html = <TEMP>;
close (TEMP);
print "$html some other text and stuff here";

This is very basic and if memory serves me right the <TEMP> will only read the first line of the file (??) I think ... anyway you get the idea.

rick
08-29-2000, 06:05 PM
You can use a template by writing an html document. In the place where you want to incert information, have a line that says something like: <!--begin-->

then in your cgi script, you would have something like this:

open(IN,"page.html") || die $!;
@text = <IN>;
close(IN);

open(MAIN,">$page.html") || die $!;
foreach $line (@text)
{
if ($line =~ /<!--begin-->/)
{
print MAIN "<!--begin-->\n";
print MAIN "more info... ";
}
else {
print MAIN "$main_line";
}
}
close(MAIN);

-----------------------
this will re-write the html file and add addtional info in the middle. Hope this helps.