[Templates] Passing $context to the providers, good or bad idea?

Yann Kerhervé yann.kerherve at gmail.com
Mon Feb 18 00:04:43 GMT 2008


Hi,

I'm in a situation where I think I need to have access to the context object
from a provider. This is not allowed with the current TT code, and I wonder
if there is a reason for it; say for instance: It's a totally bad idea.

A patch that does it for me is:

Index: dev-local-lib/Template/Context.pm
===================================================================
--- dev-local-lib/Template/Context.pm   (revision 73558)
+++ dev-local-lib/Template/Context.pm   (working copy)
@@ -136,7 +136,7 @@
             if $self->{ DEBUG };

         foreach my $provider (@$providers) {
-            ($template, $error) = $provider->fetch($shortname, $prefix);
+            ($template, $error) = $provider->fetch($shortname, $prefix,
$self);
             if ($error) {
                 if ($error == Template::Constants::STATUS_ERROR) {
                     # $template contains exception object

Which makes fetch() call very similar to the one used for Plugin and Filter
providers.

With that patch I can, in my providers, extract information from the context
(current_user, various settings) to specifically load the correct template
(or know from where to load it).

If this is a bad idea, how could I do it differently (and correctly?)

Thanks,

Yann
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.template-toolkit.org/pipermail/templates/attachments/20080217/342ccb1a/attachment.htm 


More information about the templates mailing list