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

In a nutshell:
What is the best way to call and pass parameters to an Apache::Template from a Registry handler?

I'm using Apache::Template (TT2) as the templating system but there's are a few parts done as A::Registry scripts. These do perly processing and use the same tt2 templates as the interface. I could run the templates myself but would prefer to go via A::T so the configuration is all in the httpd.conf.

That seems to leave the following options:

I'm currently using the second way which seems to work fine. (see code snippets below).

Is there anything I should look out for? Is there a better way I haven't come across?

sub try_again { my ($r,$msg) = @_; $r->pnotes(user_form_err => $msg); my $subr = $r->lookup_uri('/register.thtml'); $r->filename($subr->filename); return Apache::Template::handler($r); } sub my_handler { ... something() or return try_again($r, $msg); ... }

Replies are listed 'Best First'.
Re: Calling Apache::Template's handler directly
by perrin (Chancellor) on Jan 06, 2003 at 02:22 UTC
    There's not much value in Apache::Template if you are using Registry scripts. It's quite easy to call Template yourself and the configuration stuff is easy too. I'd say it's safer and easier than fussing with internal redirects.

    The other approach is to move the Apache::Registry scripts you have into modules that can be called from Apache::Template. There is a hook for calling your own sub that can put things into the stash before the template is called.

      Thanks.

      The reason I was trying to stick with A::T is that others will be managing the site day to day and I want them to be able to change the configuration without looking at Perl code. So easy for me is not easy for them.

      I'm using the 2nd approach to setup a user information object for the template. I'll think about putting the other functions in there. It certainly would make param handling easier.

      I like dynamically choosing the template but I guess dynamically including components will do the same.

      You're right to point out that it's starting to get messy though.

        You could actually keep the config inside httpd.conf but do it with PerlSetVar commands that you read in your code.

        I can't tell exactly what you're doing with the user information object, but the approach I was referring to uses the TT2ServiceModule option. You might want to take a look if that's not what you're doing now.

        I completely agree that running some code and then dynamically choosing a template is better, which is why I don't use Apache::Template. It's much easier to do that when you call Template directly.