Looping Nested Ordered Lists
| From: | Tim Lucas | Date: | Sun, 23 Nov 2003 15:15:26 +0000 |
| Subject: | Looping Nested Ordered Lists | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-10590@lists.php.net to get a copy of this message | ||
I have a array named $comments available in the template with keys 'text' and 'level'
For example:
$comment[0] = ( 'level' => 0, 'text' => 'comment 1' )
$comment[1] = ( 'level' => 0, 'text' => 'comment 2' )
$comment[2] = ( 'level' => 1, 'text' => 'in reply to comment 2' )
$comment[3] = ( 'level' => 2, 'text' => 'again in reply to comment 2' )
$comment[4] = ( 'level' => 3, 'text' => 'nested even deeper' )
$comment[5] = ( 'level' => 0, 'text' => 'comment 3' )
how do I do my foreach to create the following:
<ul>
<li>comment 1</li>
<li>comment 2
<ul>
<li>in reply to comment 2</li>
<li>again in reply to comment 2
<ul>
<li>nest even deeper</li>
</ul>
</li>
</ul>
</li>
<li>comment 3</li>
</ul>
to give the following:
* comment 1
* comment 2
o in reply to comment 2
o again in reply to comment 2
+ nest even deeper
* comment 3
I just can't figure out how to arrange the tags so it works properly.
Thanks,
Tim