At 16:13 30/01/2002 +0100, Oscar Serrano wrote:
<snip>
>it would be easier to him to see something like this:
>
><SELECT NAME=public>
><OPTION VALUE="y">[%true%]
><OPTION VALUE="n">[%false%]
></SELECT>
<snip>
There are various reasons why I use CGI.pm. In the example in question, the
default value for the radio buttons was going to vary depending on the
value pulled from the database. Using CGI.pm, which I'm familiar with
anyway, seemed to be the easiest way of doing it (even though I couldn't
get it to work without list assistance).
An alternative would have been to use something like
<SELECT NAME=public>
[% IF default_required == y %]
<OPTION VALUE="y" checked>[%true%]
<OPTION VALUE="n">[%false%]
[% ELSE %]
<OPTION VALUE="y" checked>[%true%]
<OPTION VALUE="n">[%false%]
[% END %]
</SELECT>
That is more complicated than using CGI.pm.
Suppose you had an array that you wanted to print in a list. You could write
<ul>
[% FOREACH d = array %]
<li>[% d %]</li>
[% END %]
</ul>
But something like
[% cgi.start_ul();
FOREACH d = array;
cgi.li("$d");
END;
cgi.end_ul()
%]
is probably simpler.
Cases where the template needs to know stuff like the query string of the
page, or the HTTP_REFERER are possible with CGI.pm, but not plain HTML.
Using CGI.pm removes all HTML logic from your templates, in the same way
that using Template Toolkit removes all display logic from your scripts. In
my experience, this makes the templates easier to use.
Another advantage about using CGI.pm is you can change the version of
(X)HTML just by changing one module, rather than hundreds of templates.
>my code is pure HTML that every body can modify.
This is also a good point. Only other programmer-type people will be
working with my templates so this isn't an issue with me. In the past I
have worked with people who have been unhappy with anything other than pure
HTML. If someone of that level was expected to maintain my templates I'd
probably not use CGI.pm so much.
Like everything else in perl, there is more than one way to do this. The
best one depends on your circumstances.
Andrew
--
Andrew McFarland
UNITE Solutions Phone 028 9077 7338
http://www.unite.net/ Fax 028 9077 7313