Hi,
On Tuesday 12 March 2002 17:35, you wrote:
> Hey Martijn --
>
> > Thanks for the idea, it works well and it doesn't increase
> > the number of
> > templates.
>
> One thing to consider: In your single template file you now have one big
> template with two parts, separated with a <TMPL_IF>. This forces you to
> make one "upstream" decision:
>
> $t->param('EXCEL' => 1) if (in_excel_mode());
>
>
> If you have to make one decision, anyway, why not instead:
>
> my $tmpl_file = (in_excel_mode()) ? 'csv.tmpl' : 'html.tmpl';
>
Actually it can be done in another way as well: if I want to create the plain
text output I add a query parameter 'plaintext=1' to the URL that calls my
CGI script. The query parameters are part of my main object and are retrieved
in most functions as follows:
my $query = $self->{'CGI'};
which is pretty standard stuff.
To create a new template object I do:
my $template = HTML::Template->new(
filename =>"zhu.thtml",
loop_context_vars => 'true',
associate => $query,
die_on_bad_params => '0',
);
By using the 'associate' argument the template gets hold of the query
parameters, sees that 'plaintext' is set and performs the appropriate loop
(<TMPL_IF NAME=PLAINTEXT> ... ).
> What is the down-side of having two separate template files? Yes, you
> would have to edit them separately -- but you really have "two files in
> one" in the single-file solution, anyway. In a single file both parts
> contain redundancies which have to be edited separately, even though they
> are in the same file!
> For the marginal advantage of only opening a single file, you now have two
> "file parts" which are each individually more complicated, as a result. It
> is now more difficult to make changes to one, because you have to concern
> yourself with the contents of the other.
There are pros and cons to both methods. I already have fifteen templates for
this app and there will be more. To keep functions together and the directory
'clean' I group stuff.
TMTOWTDI, I say.
> IMHO,
Of course, I respect that ;)
Regards,
--
+----------------------------------+
Martijn van den Burg
ASML, CS PPC Inform@tion Systems
Voice: +31 (0)40 268 3856
+----------------------------------+
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]