RE: [SMARTY] while loop in smarty like ...

From: Date: Mon, 18 Aug 2003 21:48:12 +0000
Subject: RE: [SMARTY] while loop in smarty like ...
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10091@lists.php.net to get a copy of this message
I posted a while ago about Smarty supporting an iterator interface, but it didn't go over too well ;) http://marc.theaimsgroup.com/?l=smarty-general&m=103912103817298&w=2 You could quickly hack a function together which took one of your iterator objects and a template as parameters, eg: { iterate using=$iterator template='movie_list.tpl' assign_as='movie' } // movie_list.tpl <--- <tr><td>{$movie->name}</td><td>{$movie-genre}</td></tr> // ---> the function code would move across your iterator object and call display on each element using the template you've defined, eg: function smarty_function_iterate($params,&$smarty){ $iterator = $params['using']; $tpl = $params['template']; $assign_as = $params['assign_as']; while( $element = $iterator->next() ){ $smarty->assign($assign_as,$element); $smarty->display($tpl); } } finally, your outer template would look something like: <table> { iterate using=$iterator template='movie_list.tpl' assign_as='movie' } </table> Anyhow, you'll probably need to adapt this to your own application's needs. Also, the above example isn't very cache-friendly. -mark ---------------------------- Mark Priatel Iolog Web Communications www.iolog.com -----Original Message----- From: Kai-Uwe Beyer [mailto:ksi@teamlinux.de] Sent: Monday, August 18, 2003 5:25 PM To: smarty-general@lists.php.net Subject: [SMARTY] while loop in smarty like ... Hi, is it possile to simulate a while loop like: while($movie = $movieIterator->next()){ ... } $movieIterator is an iterator over a list of objects. The method returns for instance an object or false. bye Kai -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

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