RE: [SMARTY] More complex table

From: Date: Mon, 08 Dec 2003 15:32:30 +0000
Subject: RE: [SMARTY] More complex table
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10648@lists.php.net to get a copy of this message
I spent quite a bit of time writing a block plugin to handle more complex tables. It supports controlling number of columns, as well as maximum rows. I use it to quicky create tables from database queries that were fetched associatively by converting the array indices into variables for use inside the block. Basically it works like this: php: $array[0] = array( 'one' => 'Hello', 'two' => 'Moe', 'three' => 'Shmoe' ); $array[1] = array( 'one' => 'Have', 'two' => 'fun', 'three' => 'Joe' ); tpl: <table> {html_table_cells loop=$array cols=1} {$one} {$two} {$three} {/html_table_cells} </table> output: <table> <tr><td>Hello Joe Shmoe</td></tr> <tr><td>Have fun Joe</td></tr> </table> It works fine for me, but would be great if an experienced plugin writer would take a look at it for me and work together to make it better / more efficient. I think once fine tuned it would be a great addition to the Smarty plugins distro. If anyone is interested, lmk and I'll send you the code. -Marshall ____________________________________ "If at first the idea is not absurd, then there is no hope for it." - Albert Einstein > -----Original Message----- > From: Monte Ohrt [mailto:monte@ispi.net] > Sent: Monday, December 08, 2003 9:56 AM > To: Janos Rusiczki > Cc: Smarty General > Subject: Re: [SMARTY] More complex table > > > There is no good way of handling this with html_table, and IMHO > formatting the content is out of the scope of html_table anyways. Use > the manual method of table generation, and format your data within the > loops. > > > http://smarty.php.net/contribs/examples/dynamic_table_columns/tabl > e.tpl.txt > http://www.phpinsider.com/smarty-forum/viewtopic.php?t=1266 > > > On Sat, 2003-12-06 at 11:39, Janos Rusiczki wrote: > > Hello, > > > > Say, I have the following data: > > > > $pic_fn = array('1.jpg', '2.jpg', '3'.jpg'); > > $pic_desc = array('me', 'jack', 'george'); > > $pic_info = array('1024 x 768', '800 x 600', '640 x 480'); > > > > I would like to generate a table. If I use 'html_table' I can use the > > following: > > > > {html_table loop=$pic_fn cols=2 table_attr='border="0"'} > > > > resulting in: > > > > <table border="0"> > > <tr><td>1.jpg</td><td>2.jpg</td></tr> > > </tr><td>3.jpg</td><td>&nbsp;</td></tr> > > </table> > > > > However I'd like to get something more complex, namely (from the data > > I presented above): > > > > <table border="0"> > > <tr> > > <td><img src="1.jpg" alt="me"><br />info: 1024 x > > 768</td> > > <td><img src="2.jpg" alt="jack"><br />info: 800 x > > 600</td> > > </tr> > > <tr> > > <td><img src="3.jpg" alt="george"><br />info: 640 x > > 480</td> > > <td>&nbsp;</td> > > </tr> > > </table> > > > > I think it would be a good ideea to extend 'html_table'-s > > functionality to include ways of dealing with these kinds of > > situations. > > > > Until then I'm asking for an elegant, template based, solution, > > because I have one but it involves building the whole table in PHP. > > And then, what's the point of using the template engine? :) > > > > Thanks, > > -janos- > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.smarty.general (#10648) next »