Re: is it possible to use var in include
Peter Leonard <[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.html-template |
|---|---|
| Message-ID | <[email protected]> |
Michael,
In my experience, the only way to make that work is by making two passes
through HTML::Template, creating a custom filter on the first pass.
So your template syntax would look like this:
[TMPL_INCLUDE NAME=<TMPL_VAR NAME=mod>]
The first pass would set the 'mod' param, but ignore the outer tags. The
second pass would use a filter to convert all the [TMPL] tags to standard
<TMPL> tags, and then behave as normal.
Something like the following perl-pseudo:
$tmpl->param(mod=>'include.tmpl');
my $pass = $tmpl->output();
my $tmpl2 = HTML::Template->new(scalarref => $pass,
filter =>
sub { $_ =~ s/\[(TMPL[^\]]+)\]/<$1>/gis; });
$tmpl2->param(%other_vars);
return $tmpl2->output();
HTH,
--pete
On Wed, 28 Sep 2005 [email protected] wrote:
> Hello all,
>
> Is that not possible? <TMPL_INCLUDE NAME=<TMPL_VAR NAME=mod>>
> Cause depending in which mode I open the template I want to show up a
> differnt body (e.g. start page, register page, search page...)
>
> Regards
> Michael
----
Peter Leonard
[email protected]
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl