At 11:33 AM on 12 Oct 2009, Sean McAfee wrote:

> 2009/10/12 Octavian Râşniţă <[email protected]>
> 
> > Is it possible to define a macro in a single place and access it in
> > all the templates?
> >
> This seems to work:
> 
> use Template;
> use Template::Context;
> 
> my $context = Template::Context->new;
> $context->process(\'[% MACRO foo GET 42 %]');
> 
> my $template = Template->new({ CONTEXT => $context });
> $template->process(\'[% foo %]');

Or:

use Template;

my $template = Template->new({
        PRE_PROCESS => macro_foo,
        BLOCKS => { 
                macro_foo => '[% MACRO foo GET 42 %]'
        }
}); 
$template->process(\'[% foo %]')
        || die $template->error();

...but now that I think about it, yours looks simpler. :-)  

I was hoping I could just pass a scalar ref to PRE_PROCESS (like you
can to process() ), and then BLOCKS wouldn't be necessary... but it just
errors out with "file error - SCALAR(0x8943798): not found".


-- 

C. Chad Wallace, B.Sc.
The Lodging Company
http://www.skihills.com/
OpenPGP Public Key ID: 0x262208A0

Attachment: signature.asc
Description: PGP signature

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to