CGI html table generation

J

Justin C

I've spent many years just bodging my html with the CGI module. But now
I'm trying to do it properly and I'm happy with my progress so far. What
I am having trouble with is specifying cell widths (and therefore the
width of the entire column).

I'm creating tables like this:

print table({-border=>1},
Tr({-align=>'left', -valign=>'top'},
[
td([ "foo", "bar", "baz" ]),
td([ "eenie", "meenie", "minee" ]),
td({-colspan=>'3',-align=>'center'},[
submit('Upload') . " or " . reset('Clear')
])
]
)
);

I used to set my widths with <td width="20%"> (or whatever value), but
I see that that method is now deprecated, and that we should use styles.
If that is the case, how does one, using the above table creation
method, add styles per table cell, because, from the above it appears
that cell attributes can be set only for the entire row by putting,
after "td(", {-attribute=>'setting', -other_attr=>'setting'}.

Thank you for any help you can give with this.

Justin.
 
R

RedGrittyBrick

Justin C said:
td([ "foo", "bar", "baz" ]),
I used to set my widths with<td width="20%"> (or whatever value), but
I see that that method is now deprecated, and that we should use styles.
If that is the case, how does one, using the above table creation
method, add styles per table cell,


td({-style => 'width: 20%'}, [ "foo" ]);
td({-style => 'width: 30%'}, [ "bar" ]);
td({-style => 'width: 50%'}, [ "baz" ]);

Ideally the styles would be specified in a separate CSS stylesheet
rather than embedded in the html markup.

I guess you need something like

td({-class => 'productname'}, [ "foo" ]);
td({-class => 'region'}, [ "bar" ]);

Apply the widths in your CSS stylesheet. E.g.

td.productname { width: 20%; }




<diversion>

Personally, whilst the CGI module has it's uses, I've not found it very
useful for HTML generation. After all you are still mixing your Perl
code with HTML. Things that are arguable better separated by using a
templating approach. Automatic tag completion (i.e. enforcement of very
basic HTML syntax conformance) is the only benefit I see over something like

print qq(<td class="productname">foo</td>);


The cost you pay for this benefit is the introduction of effectively a
third language. I've not been convinced it is worth it.

I do think CGI.pm is useful for handling the HTTP protocol, CGI
interface, decoding parameters etc.

</diversion>
 
H

Helmut Richter

Personally, whilst the CGI module has it's uses, I've not found it very useful
for HTML generation. After all you are still mixing your Perl code with HTML.
Things that are arguable better separated by using a templating approach.
Automatic tag completion (i.e. enforcement of very basic HTML syntax
conformance) is the only benefit I see over something like

print qq(<td class="productname">foo</td>);


The cost you pay for this benefit is the introduction of effectively a third
language. I've not been convinced it is worth it.

I do think CGI.pm is useful for handling the HTTP protocol, CGI interface,
decoding parameters etc.

I thinks so, too. Another thing I consider very useful is setting default
values for a new iteration of a form to the last values given by the
end-user, thus allowing returning a partially incorrectly filled-out form
to the user for correction and completion. This feature, however, requires
that the pertinent HTML text is generated by the functions of the CGI
module. Other HTML text may be interspersed that is directly written to
STDOUT.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top