Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Recursion

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
ion|Max
Smarty n00b


Joined: 15 Mar 2005
Posts: 3

PostPosted: Tue Mar 15, 2005 2:09 pm    Post subject: Recursion Reply with quote

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 Wink
Back to top
View user's profile Send private message
pardel
Smarty Rookie


Joined: 05 Jan 2005
Posts: 7
Location: London, UK

PostPosted: Tue Mar 15, 2005 2:44 pm    Post subject: Reply with quote

Try to call a template from itself passing the each children.

Can you paste in your template?

Paul
Back to top
View user's profile Send private message
ion|Max
Smarty n00b


Joined: 15 Mar 2005
Posts: 3

PostPosted: Tue Mar 15, 2005 6:31 pm    Post subject: Reply with quote

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 Wink

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP