{section} and associative arrays...
| From: | Mike Benoit | Date: | Wed, 10 Jul 2002 15:52:55 +0000 |
| Subject: | {section} and associative arrays... | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5247@lists.php.net to get a copy of this message | ||
I'm trying to get smarty to loop through part of an associative array, I'm sure
theres a way to do it, I just must be over looking the proper syntax.
var_dump($minor_category_rows[10]);
array(8) {
[0]=>
array(2) {
["id"]=>
int(0)
["name"]=>
string(3) "---"
}
[1]=>
array(2) {
["id"]=>
int(10)
["name"]=>
string(7) "Billing"
}
[2]=>
array(2) {
["id"]=>
int(30)
["name"]=>
string(20) "Cancellation - Price"
}
[3]=>
array(2) {
["id"]=>
int(40)
["name"]=>
string(22) "Cancellation - Service"
}
[4]=>
array(2) {
["id"]=>
int(50)
["name"]=>
string(22) "Cancellation - Product"
}
[5]=>
array(2) {
["id"]=>
int(20)
["name"]=>
string(20) "Cancellation - Other"
}
[6]=>
array(2) {
["id"]=>
int(60)
["name"]=>
string(9) "Retention"
}
[7]=>
array(2) {
["id"]=>
int(900)
["name"]=>
string(5) "Other"
}
}
The second {section} tag is where I'm running in to problems. If I replace
"$major_category_rows[major_categories].id" with "10" it loops through each of
the above array elements, however I still can't figure out how to print the
[name] of each element, and have Smarty do the proper nested looping.
Any ideas how I should do this?
<table width="100%" cellspacing="1" cellpadding="2"
border="0">
<tr>
{section name=major_categories loop=$major_category_rows}
<td bgcolor="{#table_row_bgcolor#}" valign="top">
<div align="left">
{$major_category_rows[major_categories].name}
{section name=minor_categories
loop=$minor_category_rows[$major_category_rows[major_categories].id]}
{$minor_category_rows[minor_categories].name}
{/section}
</div>
</td>
{if %major_categories.iteration% % 2 == 0}
</tr>
<tr>
{/if}
{/section}
</tr>
</table>
Thanks.