* Ken Clark <[EMAIL PROTECTED]> [2002-04-26 14:33]: > I'll throw my technique into the ring, too. I use Template Toolkit > most of the time, and I pass the original Apache request object back > to the template as a parameter. Then I call the "param" method to > fill in the "value" of form elements, like so:
[-- snip --] > Nothing gets placed there the first time through as calling > "$apr->param" returns nothing. This seems to work great for me. I've > not used HTML::Template in a while, but possibly you can do this, too? The constructor for HTML::Template takes an optional argument names "associate", which should point to an object (or reference to a list of objects) that can("param"). Paramters in the template that are not explicitly filled in using the param method of the HTML::Template object are looked for by iterating through this list and calling param($template_variable_name), and takes the first non-false value as the correct one. To reuse Ken's illustration: > In code: > > sub handler { > my $r = shift; > my $apr = Apache::Request->new($r); > my $t = Template->new; > my $html; > $t->process('/foo/bar.tmpl', { apr => $apr }, \$html); > $apr->content_type('text/html'); > $apr->send_http_header; > $apr->print( $html ); > return OK; > } sub handler { my $r = shift; my $apr = Apache::Request->new($r); my $t = HTML::Template->new(associate => $apr, filename => '/foo/bar.html'); $apr->content_type('text/html'); $apr->send_http_header; $apr->print( $t->output ); return OK; } > In template: > > <form> > <input name="foo" value="[% apr.param('foo') %]"> > <textarea name="text">[% apr.param('description') %]</textarea> > </form> <form> <input name="foo" value="<TMPL_VAR NAME="foo">"> <textarea name="text"><TMPL_VAR NAME="description"></textarea> </form> For the template itself, "foo" will be looked for as $apr->param("foo"), and description as $apr->param("description"). (darren) PS Hi Ken! -- The more we disagree, the better the chance that one of us is right.