Thanks for the suggestions, but both of them error out with: file error - ablock: not found Josh Rosenbaum <josh-2KZaVHFycl6akBO8gow8eQ@xxxxxxxxxxxxxxxx> wrote:
John Smith wrote: > I want to be able to include a template component in a template where > that component is not a file. I'm sure its somewhere in the man pages, > but I can't find it. This is what I tried: > > perl code: > use strict; > use Template; > my $block = <> ---------------------------------------------- > Hello, [% name %] > ---------------------------------------------- > BLOCK > my $tt = Template->new() or die; > my $ttData = > { > blockdata => $block, > name => 'John' > }; > $tt->process("testblock.tt", $ttData) or die; > > testblock.tt: > [% MACRO ablock BLOCK %] > [% blockdata %] > [% END %] > [% I
NCLUDE ablock %] > > Doesn't work. Any ideas? > John Smith >
Hi John,
I probably shouldn't post on this as I haven't tried what you mentioned. However, have you tried adding an "| eval" to the blockdata variable retrieve? My guess is that you are just getting the non-processed block you specified in the perl code above. (Let us know what you mean by "doesn't work" if it's not it.) :)
testblock.tt: [% MACRO ablock BLOCK %] [% blockdata | eval %] [% END %] [% INCLUDE ablock %]
As an alternative you might try the following, which I have also not tested, and am not sure will even work, but am just providing as something you can try. I've never tried two procesess, in a row, and am not sure whether they will have the same context or not, but if it worked, it'd be a simpler solution.
================================================= perl code: use strict; use Template; my $block = <
[% BLOCK ablock %] ---------------------------------------------- Hello, [% name
%] ---------------------------------------------- [% END %] BLOCK my $tt = Template->new() or die; my $ttData = { blockdata => $block, name => 'John' }; my $result; $tt->process(\$block, $ttData, \$result) or die; $tt->process("testblock.tt", $ttData) or die;
testblock.tt: [% INCLUDE ablock %] =================================================
-- Josh
_______________________________________________ templates mailing list templates-MnLy+PD7ppGDO3lXZvfOKmD2FQJk+8+b@xxxxxxxxxxxxxxxx http://lists.template-toolkit.org/mailman/listinfo/templates
__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
|