CGI html table generation

Discussion in 'Perl Misc' started by Justin C, Mar 3, 2010.

  1. Justin C

    Justin C Guest

    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.
     
    Justin C, Mar 3, 2010
    #1
    1. Advertising

  2. On 03/03/2010 13:16, Tad McClellan wrote:
    > Justin C<> 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
     
    RedGrittyBrick, Mar 3, 2010
    #2
    1. Advertising

  3. 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
     
    Helmut Richter, Mar 3, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Al Wilkerson
    Replies:
    1
    Views:
    2,769
    =?Utf-8?B?U2FyYXZhbmFuIEsgVg==?=
    Mar 14, 2005
  2. Alex Hunsley
    Replies:
    2
    Views:
    388
    Steve Holden
    Jun 4, 2004
  3. Brian Quinlan

    CGI documentation generation

    Brian Quinlan, Oct 29, 2004, in forum: Python
    Replies:
    0
    Views:
    271
    Brian Quinlan
    Oct 29, 2004
  4. John W. Long

    HTML Generation (Next Generation CGI)

    John W. Long, Nov 22, 2003, in forum: Ruby
    Replies:
    4
    Views:
    377
    John W. Long
    Nov 24, 2003
  5. Josef 'Jupp' Schugt

    (Ab)using class CGI as non-CGI HTML generator?

    Josef 'Jupp' Schugt, Mar 5, 2005, in forum: Ruby
    Replies:
    3
    Views:
    283
    Lee Braiden
    Mar 6, 2005
Loading...

Share This Page