develooper Front page | perl.beginners | Postings from January 2002

CGI::FastTemplate confusion

Thread Next
January 7, 2002 13:37
CGI::FastTemplate confusion
Message ID:
Hello all,

I've just begun to use CGI::FastTemplate and I get the feeling I am misunderstanding
something.  I have read the perldoc repeatedly, but I guess it's just not
sinking in.  If anyone can lend some insight, it would be much appreciated.

I have done the following:

1) Created an HTML template file which contains HTML code (of course) and
the names of variables that are populated in my script.  For example, if
the following line is in my template file:

<td>Hello $name</td>

Then somewhere in my perl script, you will find:

my $name = "Ian";

2) Included the following in the perl script:

$tpl->define( main   => "filename.tpl");
$tpl->parse( PAGE  => "main");

I get the feeling I am misinterpreting how CGI::FastTemplate works, but
what I see is that the script does indeed print my template file, but does
not replace any of my variables at all (with strict on, I can see them in
the output quite clearly).  So I am left to wonder, did I just make a silly
mistake, or did I misinterpret how it works?  That is, I believe I am most
confused by the syntax of $tpl->parse().  Does this just tell FastTemplate
to parse the template file and replace the variables with those in the script,
or do I have to actually define a separate variable for each one I want
FastTemplate to replace?  In the code above, I picked "PAGE" as an arbitrary
name representing my template with all variables replaced.  Should this
instead be the name of a variable in itself that I want parsed in the template,
meaning I need to call $tpl->parse() for each and every one of my variables?

I hope I have been clear.  Again, any insight into my confusion is appreciated.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About