On Fri, Oct 05, 2001 at 03:37:00PM -0500, Boex,Matthew W. wrote:
>hello,
>
>i have a basic question.  i have created a couple cgi's and want to use
>HTML::Template with them.  can someone explain or send an example of the
>associate option.  it seems like i should be using that but don't quite get
>it from the doc's.

You don't say what you're trying to achieve. The associate option is 
usually used to let template values be filled in automatically from a 
CGI query - i.e. you want to display what the user has just entered.  
(You might do this to re-present a form which hasn't had required 
fields completed, or to ask for confirmation of the user's entry before 
acting on it.)

If the associate option didn't exist, and the form that called the
script had set the variables foo, bar and baz, then you could do:

my $query=new CGI;
my $template=HTML::Template->new(filename => 'template.tmpl');

$template->param(foo => $query->param('foo'));
$template->param(bar => $query->param('bar'));
$template->param(baz => $query->param('baz'));

The associate option is a short-cut to this - the same effect as above
(though for _all_ parameters in the query that the script receives) is
given by the code:

my $query = new CGI;
my $template = HTML::Template->new(filename => 'template.tmpl',
                                   associate => $query);

That's all there is to it.

Hope this is of help,

Roger

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to