Re: FW: [htmltmpl] how to display data in four columns
Brought to you by:
samtregar
From: Cees H. <ce...@si...> - 2003-01-16 20:52:17
|
Quoting "Kapoor, Nishikant X" <Nis...@xc...>: > Chris has suggested a very fine solution. Some of you might find it crossing > the presentation line but it seems to be pretty generic in nature. If you want to leave the decision of how many columns to use to the Template Designer, then you can solve this problem with the HTML::Template::Expr module and the use of the % (modulus) operator and the __counter__ loop context variable. here is a quick example that uses 4 columns: #!/usr/bin/perl use strict; use warnings; use HTML::Template::Expr; my $html = <<'EOL'; <table> <tr><TMPL_LOOP NAME="DATA"> <td> <TMPL_VAR NAME="VALUE"> </td><TMPL_UNLESS EXPR="(__counter__ % 4) || (__last__)"> </tr> <tr></TMPL_UNLESS></TMPL_LOOP></tr> </table> EOL my $t = HTML::Template::Expr->new(scalarref => \$html, loop_context_vars => 1); $t->param(data => [ map { {value => $_} } ('a'..'z') ] ); print $t->output; If the template designer wants more columns, just change the 4 to something else... You have to balance the usefulness of this against the added complexity in the template. Some Designers might scoff at the extra complexity, and others might love the flexibility it provides. Cees > > > -----Original Message----- > > From: Chris Brown [mailto:ch...@ty...] > > Sent: Thursday, January 16, 2003 1:08 PM > > To: Kapoor, Nishikant X > > Subject: Re: [htmltmpl] how to display data in four columns > > > > > > I've done this before by setting an extra flag on the nth > > column in my > > perl code. > > > > Say if I was building my loop out of a database query > > > > #.. db stuff here .. > > my $count = 0; > > my @loop = (); > > while($row = $sth->fetchrow_hashref()) { > > if($count == $nth_number_here) { > > $row->{flag} = 1; > > $count = 0; > > } > > push(@loop,$row); > > $count++; > > } > > > > # init template here > > $template->param(loop=>\@loop); > > > > # output ... > > > > > > And then in the template side something very similar to what to had > > <tr> > > <tmpl_loop name=loop> > > <td><tmpl_var name=some_db_field></td> > > <tmpl_if name=flag> > > </tr><tr> > > </tmpl_if> > > </tmpl_loop> > > </tr> > > > > Hope that helps. > > Chris > > > > Kapoor, Nishikant X wrote: > > > I guess I was not very clear in my question. Here is some > > more explanation. > > > > > > Yes, displaying variables is indeed a function of HTML but > > I was hoping to get some suggestions about displaying the > > data in four columns. The html code that I use for displaying > > data in two columns is: > > > > > > <tmpl_loop name=eventLoop> > > > <td width="50%"> > > > <tmpl_var name=eventTitle> > > > </td> > > > <tmpl_unless __odd__> > > > </tr> > > > <tr> > > > </tmpl_unless> > > > </tmpl_loop> <!-- eventLoop --> > > > > > > Has anyone used similar construct for displaying data in > > four (or n for that matter) columns ? > > > > > > Thanks > > > Nishi > > > > > > > -- > > Chris Brown > > Web Application Developer > > Ballistic Web Design > > http://ballisticwebdesign.com/ > > 903-533-8666 > > > > ------------------------------------------------------- > This SF.NET email is sponsored by: Thawte.com > Understand how to protect your customers personal information by > implementing > SSL on your Apache Web Server. Click here to get our FREE Thawte Apache > Guide: http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0029en > _______________________________________________ > Html-template-users mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/html-template-users > |