|
|
Choosing A Webhost: |
Re: Global vars management in templates: msg#00104lang.perl.modules.cgi-appplication
On 2005-09-13, Wojciech Pietron <W.Pietron-p5lsV2tsnzvVItvQsEIGlw@xxxxxxxxxxxxxxxx> wrote: > Hello, > > sorry if someone has already mentioned that problem recently. Give me a > link if it has been already discussed. > > There are some variables that I would like to have defined in all templates > I am going to use, ie. name of the user, url, sysdate etc. > > The question is: what is the simplest/best practice to maintain global > template > variables and not redefine them all after loading a new template? I am > specially interested in CAP::AnyTemplate environment. Michael Graham and I sketched out a simple plugin for this, but didn't publish the final proposed API. Or rather, at one point I did prepare wiki updates for this, but lost them was too frustrated at the time to re-write them. I now use a load_tmpl() call back for this. I would like to create a simple plugin that does the same thing in the future. In my case I'm passing in all the configuration variables and giving them the prefix "cfg_". ( This may need the 4.04 development release to work properly...I should just go ahead and declare that stable. ). sub cgiapp_init { $self->add_callback('load_tmpl',\&load_tmpl_callback); } sub load_tmpl_callback { my $self = shift; my $ht_params = shift; my $tmpl_params = shift; my $tmpl_file = shift; my %CFG = $self->cfg; # supply global config variables to the templates. Rather than pollute the name space # let's prefix them with cfg_. my %new_tmpl_params = ( %prefixed_cfg, %$tmpl_params ); for my $key (keys %new_tmpl_params) { $tmpl_params->{$key} = $new_tmpl_params{$key}; } } -- http://mark.stosberg.com/ --------------------------------------------------------------------- Web Archive: http://www.mail-archive.com/cgiapp-svx1JCNWaqPWzzAP45jFb16hYfS7NtTn@xxxxxxxxxxxxxxxx/ http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2 To unsubscribe, e-mail: cgiapp-unsubscribe-svx1JCNWaqPWzzAP45jFb16hYfS7NtTn@xxxxxxxxxxxxxxxx For additional commands, e-mail: cgiapp-help-svx1JCNWaqPWzzAP45jFb16hYfS7NtTn@xxxxxxxxxxxxxxxx
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | RE: Is there a better C::A design pattern, Barry Moore |
|---|---|
| Next by Date: | CGI::Application::Plugin::Authentication - new release, Cees Hek |
| Previous by Thread: | Re: Global vars management in templates, Michael Graham |
| Next by Thread: | RFC: CGI::Application::Plugin::MessageStack, Jason Purdy |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |