Emmanuel Quevillon writes:
> I am quite new to template toolkit.
> I a trying to include a template into another one and use
> PROCESS to do it.
>
> my first template (A) has some html code
> my second template (B) has some html code too.
>
> This how I try to use it:
>
> A:
> ===
>
> <html>
> ...
> [% FOREACH foo IN bar %]
> ..
> [% PROCESS B item = foo.items %]
> ...
>
> [% END %]
> ...
> </html>
>
> B:
> ===
>
> [% FOREACH i IN item %]
>
> [% i.name %]
>
> [% END %]
>
>
> However, doing it this way, it returns nothing at all, not
> even the HTML code produced before the PROCESS directive.
> I know, from the Manual, that it is possible to pass some
> parameters to PROCESS.
>
> So I wonder if I am doing something wrong?
There's nothing wrong with the templates you provided. Let me demonstrate
by converting it to a fully functional program:
----------------------------------------------------------------------
#!perl -w
use Template;
my $t = Template->new();
$t->process(\*DATA) || die $t->error(), "\n";
__DATA__
[% BLOCK B %]
[% FOREACH i IN item %]
[% i.name %]
[% END %]
[% END %]
<html>
[% bar = [ {items => [ {name=>'Emmanuel'},{name=>'Harald'} ] } ,
{items => [ {name=>'Quevillon'},{name=>'Joerg'} ] } ,
]
%]
...
[% FOREACH foo IN bar %]
..
[% PROCESS B item = foo.items %]
...
[% END %]
</html>
----------------------------------------------------------------------
If you get no output at all, then you should inspect the error from
the process() call to TT, like in my example code. With complicated
data structures like that it is too easy to miss some bracket...
--
Cheers,
haj
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates