mpolito1969 has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

I've got a small question about accessing method "config" of HTML::Template from CGI::Application.

I'd like to do the equivalent of HTML::Template-> config(utf8 => 1) in a CGI::Application: what's the syntax for the method call?

I know I could use a reference to an object returned by load_tmpl() but this means I have to call load_tmpl() and only then I can configure the module:
my $self = shift; my $tmplObj = $self->load_tmpl('myFile.tmpl', utf8 => 1); $tmplObj->config(utf8=>1);

Is this the best way? Can't I put the "config" call in other place so that its effect is already there when I call load_tmpl() in the first run mode?

Thanks

Bye,
Max

  • Comment on How to access HTML::Template methos "config" from CGI::Application
  • Download Code

Replies are listed 'Best First'.
Re: How to access HTML::Template method "config" from CGI::Application
by Anonymous Monk on Sep 19, 2016 at 23:05 UTC

    Can't I put the "config" call in other place so that its effect is already there when I call load_tmpl() in the first run mode?

    Make your own method that calls load_tmpl with the defaults your want

    You don't even have to use hook mechanism

    sub lt { shift()->load_tmpl( @_, utf8 => 1 ); }

    Or use the CGI::Application::Plugin::AnyTemplate plugin as it supports configuration of template drivers

      This is a nice workaround, thank you for your answer.

      Ciao,
      Max