|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
ion|Max Smarty n00b
Joined: 15 Mar 2005 Posts: 3
|
Posted: Tue Mar 15, 2005 2:09 pm Post subject: Recursion |
|
|
I have an array like that:
Code: | array
0 =>
array
0 => '2'
'id' => '2'
1 => '0'
'parent_id' => '0'
2 => 'GaW Abi 2007'
'name' => 'GaW Abi 2007'
1 =>
array
0 => '3'
'id' => '3'
1 => '0'
'parent_id' => '0'
2 => 'GaW'
'name' => 'GaW'
2 =>
array
0 => '4'
'id' => '4'
1 => '2'
'parent_id' => '2'
2 => 'vcxvvxycvcxcy'
'name' => 'vcxvvxycvcxcy'
3 =>
array
0 => '5'
'id' => '5'
1 => '0'
'parent_id' => '0'
2 => 'q'
'name' => 'q'
|
I want to display it with the fun/defun syntax, but I create just loops with no end!
The Output should look like an traditional tree.
I hope you can help me!
Excuse my English, I know it's not very good |
|
Back to top |
|
pardel Smarty Rookie
Joined: 05 Jan 2005 Posts: 7 Location: London, UK
|
Posted: Tue Mar 15, 2005 2:44 pm Post subject: |
|
|
Try to call a template from itself passing the each children.
Can you paste in your template?
Paul |
|
Back to top |
|
ion|Max Smarty n00b
Joined: 15 Mar 2005 Posts: 3
|
Posted: Tue Mar 15, 2005 6:31 pm Post subject: |
|
|
I found a solution, but it spent a lot of time. I gave up but I started ist a last tiem and it went on
Code: | {defun name="folders"}
{if $start == true}
{foreach from=$folders item=current_folder}
{if $current_folder.parent_id == $search}
<tr>
<td>{section loop=$indent name="indent"}&&&{/section}& {$current_folder.name}</td>
</tr>
{fun name="folders" start=true search=$current_folder.id indent=$indent+1}
{/if}
{/foreach}
{/if}
{/defun}
<ul>
<table cellpadding="3">
{foreach from=$folders item=current_folder}
{if $current_folder.parent_id == 0}
<tr><td>{$current_folder.name}</td></tr>
{fun name="folders" start=true search=$current_folder.id indent=1}
{/if}
{/foreach}
</table> |
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|