Ok, I think it's because you are using [% INCLUDE ablock %] rather than just [% ablock %].
From:
http://www.template-toolkit.org/docs/plain/Manual/Directives.html

A Macro doesn't appear to use the INCLUDE.

-- Josh

John Smith wrote:
Thanks for the suggestions, but both of them error out with: file error - ablock: not found

*/Josh Rosenbaum <[EMAIL PROTECTED]>/* 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 %]
     > [% INCLUDE 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
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to