Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > CGI html table generation

Reply
Thread Tools

CGI html table generation

 
 
Justin C
Guest
Posts: n/a
 
      03-03-2010
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.

--
Justin C, by the sea.
 
Reply With Quote
 
 
 
 
RedGrittyBrick
Guest
Posts: n/a
 
      03-03-2010
On 03/03/2010 13:16, Tad McClellan wrote:
> Justin C<(E-Mail Removed)> wrote:
>
>> 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>

--
RGB
 
Reply With Quote
 
 
 
 
Helmut Richter
Guest
Posts: n/a
 
      03-03-2010
On Wed, 3 Mar 2010, RedGrittyBrick wrote:

> 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.

--
Helmut Richter
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with Dynamic Html Table control generation Al Wilkerson ASP .Net 1 03-14-2005 11:05 AM
(Ab)using class CGI as non-CGI HTML generator? Josef 'Jupp' Schugt Ruby 3 03-06-2005 11:34 AM
CGI documentation generation Brian Quinlan Python 0 10-29-2004 12:15 PM
anything in python to aid generation of html for CGI? Alex Hunsley Python 2 06-04-2004 01:13 PM
HTML Generation (Next Generation CGI) John W. Long Ruby 4 11-24-2003 04:24 AM



Advertisments