Chris Petersen wrote:
> I'm having trouble finding documentation describing how to import  
> functions into the TT namespace without using "use" from within the  
> template itself.  My application has a bunch of functions that I'd  
> like to make available to our template team (some of whom are non- 
> technical marketing types) without them having to think about "use".

Hi Chris,

You can pass the functions by reference as template variables.

     $vars = {
        foo => \&Your::App::foo,
        bar => \&Your::App::bar,
     };
     $tt->process($template, $vars);

You can also define them up-front when you create the Template object
to save having the pass them over every time you do a process().

     my $tt = Template->new({
         VARIABLES => {
            ...
         }
     });

Or you can create your own Template subclass which adds them in via the
new() method.

   package Your::Template;
   use base 'Template';

   sub new {
       my $class  = shift;
       my $config = @_ && ref $_[0] eq 'HASH' ? shift : { @_ };
       $config->{ VARIABLES } = {
        ...
       };
       return $class->SUPER::new($config);
   }

Then you can use Your::Template module instead of Template and the variables
will be there by default.

HTH
A

_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to