From: Justin C on
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.
From: Tad McClellan on
Justin C <justin.0911(a)purestblue.com> 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" ]);


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
From: RedGrittyBrick on
On 03/03/2010 13:16, Tad McClellan wrote:
> Justin C<justin.0911(a)purestblue.com> 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
From: Helmut Richter on
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