Eric Moore wrote:
>
> In the past, I have done what Cory outlines
>
> > From: "Cory Trese" <[EMAIL PROTECTED]>
> >>> SNIP >>
> >
> > # install global variable values from config file
> > $service_name = %conf->{'service_name'};
> > $service_url = %conf->{'service_url'};
> > $session_life = %conf->{'session_life'};
> > $session_context = %conf->{'service_id'};
> >
> > << SNIP <<
>
> in HTML::Template by doing
>
> while( ( $key, $value ) = each( %$conf ) ){
> $template->param( $key => $value );
> }
>
> How would I peform the above in CGI-APP using the paired values from the
> PARAMS parameter set in the cgi? (e.g. $myapp = MyApp->new( PARAMS =>
> \%global_params)
Eric,
If you want to do is to have the same global configuration variables
available in all your
templates you use with CGI::Application, you might want to override the
default load_tmpl() function to do that for you. Something like this:
sub load_tmpl {
my $self = shift;
my ($tmpl_file, @extra_params) = @_;
my $fq_tmpl_file = $self->tmpl_path() . $tmpl_file;
require HTML::Template;
# set up the templates with some defaults
# %CFG is global config hash
# this key is a reference to hash of HTML::Template defaults
# including die_on_bad_params=>0
my $t = HTML::Template->new_file($fq_tmpl_file, @extra_params, %{
$CFG{HTML_TMPL_DEFAULTS} });
# supply global config variables to the templates. Rather than pollute
the name space
# let's prefix them with cfg_.
$t->param(
map {
my $k = $_;
'CFG_'.$k => $CFG{$k};
} keys (%CFG)
);
return $t;
}
-mark
. . . . . . . . . . . . . . . . . . . . . . . . . .
Mark Stosberg Principal Developer
[EMAIL PROTECTED] Summersault, LLC
765-939-9301 ext 223 website development
. . . . . http://www.summersault.com/ . . . . . . .
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]