RE: [SMARTY] Re: How to generate a 3-column-table layout from anarray of pictures.

From: Date: Thu, 05 Dec 2002 20:44:16 +0000
Subject: RE: [SMARTY] Re: How to generate a 3-column-table layout from anarray of pictures.
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6664@lists.php.net to get a copy of this message
I think problems like this illustrate why function calling in templates would be desirable. In my mind, it seems to make more sense to be able wrap an array in some sort of Iterator class which handles position evaluation, than to dirty the template with math formulas. I think that originally, the argument against function calling was that it wasn't designer friendly, but obviously "{if not ($smarty.section.numloop.rownum mod $cols)}" isn't much better. Eg: class IntervalIterator{ function Iterator($array, $rowlen); function next(); function isInterval(); function data(){ return $array; } function hasNext(); } $smarty->assign("iterator", new IntervalIterator($array) ); <TABLE border=1> <TR> {section name=numloop loop=$iterator->data()} <TD>{$iterator->next()}</TD> {if $iterator->endOfRow()}</TR><TR>{/if} {/section} </TABLE> Obviously, I've left out several implementation details, but I think both developers and designers would find it easier to work with arrays if positioning details were delegated to an iterator. Ideally, a special looping block construct could be created which manipulates an iterator. {iterate using=$iterator assign=$current} {/iterate} This way, the iterate block could worry about calling hasNext(), and assigning the value of next() to '$current', etc. Furthermore, smarty could come with several generic iterator classes which could deal with most of the common uses. I just wanted to throw out some of these ideas since many of the questions on this list deal with looping over arrays. Even if function calling is still considered a bad thing, a lot the position evaluation stuff could be taken care of by the {iterate} block. Anyhow, I'd be happy to put some work into this idea, if people think it's solving a problem without breaking Smarty's design philosophy. -mark > -----Original Message----- > From: Monte Ohrt [mailto:monte@ispi.net] > Sent: Thursday, December 05, 2002 3:09 PM > To: David Eisenhart > Cc: smarty-general@lists.php.net > Subject: Re: [SMARTY] Re: How to generate a 3-column-table layout from > anarray of pictures. > > The template engine can handle this. Assign your data in a single array, > and let the template do the formatting. > > example here: > http://smarty.php.net/contribs/examples/dynamic_table_columns/table.tpl. tx > t > > Monte > > On Thu, 2002-12-05 at 11:35, David Eisenhart wrote: > > "Geoffrey Hoffman" <ghoffman@aztrib.com> wrote in message > > > I didn't see fmod() > > > in the code sample David posted, so this might be an alternative. > > > > basically my code uses the same technique - deal with each full row in > turn > > and then take on any incomplete row at the end; didn't think of using > fmod() > > so dealt with the last row issue using a couple of vars and some php > > code (will probably replace this bit with fmod now) > > > > cheers, > > David Eisenhart > > > > > > > > > > > > > > > -- > Monte Ohrt <monte@ispi.net> > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

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