Re: [SMARTY] Help in <can't describe it> appreciated

From: Date: Sun, 23 Feb 2003 05:43:41 +0000
Subject: Re: [SMARTY] Help in <can't describe it> appreciated
References: 1 2  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-831@lists.php.net to get a copy of this message
or, for an arbitrary depths of sets: php: <?php require('../site.php'); /* copied from jason: */ $d = array( 2 => array( 'enums' => array(6 => 'blue',5 => 'yellow',7 =>'red') ,'name' => 'color' ) ,11 => array( 'enums' => array(15 => 'polyester',13 => 'cotton') ,'name' => 'material' ) ,1 => array( 'enums' => array(9 => 'S',8=>'M',11=>'L', 10=>'XL') ,'name' => 'size' ) ); $d_keys = array(11,1,2); /* or array_keys($d) if order was correct :) */ $smarty->assign('d', $d); $smarty->assign('d_keys', $d_keys); $smarty->assign('i', 0); $smarty->assign('depth', sizeof($d_keys)); $smarty->display('recurse.tpl'); ?> recurse.tpl: {if ($i<$depth)} {assign var=d_key value=$d_keys.$i} <table border="1"> {if ($i<($depth-1))} {* body of recursion *} <tr><th colspan="2">{$d.$d_key.name}</th></tr> {foreach from=$d.$d_key.enums item=v} <tr> <td>{$v}</td> <td> {math assign=i2 equation="i + 1" i=$i} {include file="recurse.tpl" i=$i2} </td> </tr> {/foreach} {else} {* last recursion *} <tr><th>{$d.$d_key.name}</th></tr> {foreach from=$d.$d_key.enums item=v} <tr> <td>{$v}</td> </tr> {/foreach} {/if} </table> {else} {* end of recursion *} {/if} have fun messju On Sat, Feb 22, 2003 at 09:53:16PM -0600, Jason Sweat wrote: > php: > $t = new Smarty; > > $d = array( > 2 => array( > 'enums' => array(6 => 'blue',5 => 'yellow',7 > =>'red') > ,'name' => 'color' > ) > ,11 => array( > 'enums' => array(15 => 'polyester',13 => 'cotton') > ,'name' => 'material' > ) > ,1 => array( > 'enums' => array(9 => 'S',8=>'M',11=>'L', > 10=>'XL') > ,'name' => 'size' > ) > ); > $t->assign(array( > 'mat' => $d[11] > ,'col' => $d[2] > ,'siz' => $d[1] > )); > $t->display('test.tpl'); > > template: > <table border="1"> > {foreach from=$mat.enums item=cur_mat key=key_mat name=mat} > {if $smarty.foreach.mat.first} > <tr><th colspan="2">{$mat.name}</th></tr> > {/if} > <tr valign="top"><td>{$key_mat} => {$cur_mat}</td> > <td><table border="1"> > {foreach from=$siz.enums item=cur_siz key=key_siz name=siz} > {if $smarty.foreach.siz.first} > <tr><th colspan="2">{$siz.name}</th></tr> > {/if} > <tr valign="top"><td>{$key_siz} => {$cur_siz}</td> > <td><table border="1"> > {foreach from=$col.enums item=cur_col key=key_col name=col} > {if $smarty.foreach.col.first} > <tr><th colspan="2">{$col.name}</th></tr> > {/if} > <tr valign="top"><td>{$key_col} => {$cur_col} > {/foreach} > </table> > </td></tr> > {/foreach} > </table> > </td></tr> > {/foreach} > </table> > > ----- Original Message ----- > From: "Joscha Feth" <joscha@feth.com> > To: <smarty-general@lists.php.net> > Sent: Saturday, February 22, 2003 12:05 PM > Subject: [SMARTY] Help in <can't describe it> appreciated > > > > Please read here, I put together a small description of my problem - all > > thoughts, ideas, advises, better methods, etc. appreciated (I am nearly > > getting crazy with this thing) > > > > http://www.feth.com/uploads/case_study1.html > > > > Greets, > > Joscha

« previous php.smarty.dev (#831) next »