On Tue, Apr 23, 2002 at 07:04:52PM +0200, Christoph Sartorius wrote:
> Hi!
> I want to include a file with the TMPL_INCLUDE, but I want the filename to be
>variable, so the included file depends on some variables in the script.
> I tried the following:
> ____________________________________________
>
> Template-File:
> <TMPL_INCLUDE NAME="PATH_TO_CONTENT_FILE">
> Scipt:
> $template->param(
> PATH_TO_CONTENT_FILE => 'my_template.tmpl',
> );
> ____________________________________________
>
> Template-File:
> <TMPL_INCLUDE NAME="<TMPL_VAR ESCAPE=HTML NAME="PATH_TO_CONTENT_FILE">">
> Script:
> $template->param(
> PATH_TO_CONTENT_FILE => 'my_template.tmpl',
> );
> ____________________________________________
This can be done with a filter.
I'll example you the basic idea (Hey, I like the transformation of example
into a verb). You may want to grep the archives for others.
The point is that you use the filter to replace your token
"TMPL_DYNAMIC_INCLUDES", which could, and probably should, be called
something else since it is not an HTML::Template token, with a set of tokens
that H::T understands. Read the docs for more info.
Template File:
<TMPL_DYNAMIC_INCLUDES>
Script:
my @dynamic_includes = qw(apple.tmpl peach.tmpl pear.tmpl);
sub filter_sub {
my $tmpl_ref = shift;
my $str = join("", map { qq[<tmpl_include name="$_">\n] } @dynamic_includes);
$$tmpl_ref =~ s/<TMPL_DYNAMIC_INCLUDE>/$str/g;
}
my $t = HTML::Template->new(filename => 'filename.tmpl',
filter => {
sub => \&filter_sub,
format => 'scalar'
}});
-Gyepi
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]