Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: CGI::Application and HTML::Template interaction

by cees (Curate)
on Jan 11, 2004 at 22:07 UTC ( [id://320537]=note: print w/replies, xml ) Need Help??


in reply to CGI::Application and HTML::Template interaction

You already have the correct answer above, but there are other ways of dealing with this if you get tired of always having to pass those parameters when you call load_tmpl.

If all your templates need the loop_context_vars parameter set, then I would override the load_tmpl method to always provide it for you.

################# # load_tmpl # ################# # # Over ride the CGI::Application load_tmpl method so that # we can automatically add our own parameters to all # templates # sub load_tmpl { my $self = shift; my $template_name = shift; my %options = @_; # Turn off 'die_on_bad_params' unless it has been explicitely set $options{die_on_bad_params} = 0 unless defined $options{die_on_bad_params}; # Turn on 'loop_context_vars' unless it's been explicitely disabled $options{loop_context_vars} = 1 unless defined $options{loop_context_vars}; # Load the template using the real CGI::Application load_tmpl method my $template = $self->SUPER::load_tmpl($template_name, %options); return $template; }

- Cees

Replies are listed 'Best First'.
Re: Re: CGI::Application and HTML::Template interaction
by geektron (Curate) on Jan 12, 2004 at 14:11 UTC
    thanks, but that's my last resort, as all the other in-house apps use CGI::Application and i don't want to go making global 'company' changes without knowing the repercussions.

      You don't have to be that drastic with the change... You can add this function your any of your CGI::Application subclasses and have it work for you. You don't have to edit the CGI::Application source to add this.

      To use CGI::Application you need to write a module that inherits from CGI::Application (by adding 'use base CGI::Application;' to the top of your module). You can add the custom load_tmpl function to this module (right along side your runmodes) and it will work properly.

      The way I usually do it (and the way most CGI::Application users recommend) is to create a project wide Base class that inherits from CGI::Application, where you can customize the functionality of CGI::Application for the entire project (adding session management, authentication, etc...). Then you can create several modules with runmodes that inherit from your Base class. The Base class is where you would ideally put the customized load_tmpl method. This way your entire project gets the benefit of the change, but other users of CGI::Application on the system will not notice a difference.

      If you would like a detailed example of how this is implemented, let me know and I'll put something together for you.

      - Cheers

        The Base class is where you would ideally put the customized load_tmpl method. This way your entire project gets the benefit of the change, but other users of CGI::Application on the system will not notice a difference.
        I didn't even think of overriding other CGI::Application methods. Yes, I already have a subclass of CGI::Application for the app in question, but I hadn't gotten to the point of changing any default behaviour in methods ( because, frankly, I don't know it well enough to want to jump too far into it ). But, next time around ( and if i get a chance to refactor this project ), I'll do just that: have a customized my_load_tmpl() method that acts just like load_tmpl() with a few added fun things.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://320537]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-24 08:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found