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

Use global variables in a nested function

 
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 -> General
View previous topic :: View next topic  
Author Message
rickyheijnen
Smarty n00b


Joined: 18 May 2015
Posts: 2

PostPosted: Mon May 18, 2015 11:32 am    Post subject: Use global variables in a nested function Reply with quote

Hi,

I want to call a function that is nested in the same function to build something like a tree. Unfortunatly I can't assign the ID's in an array. I tried to make it global, but that only saves the first state of the array.

Let me show you. This is the code:
Code:
{function nest id="root"}
   {append var="nesting" value=$id scope="global"}
   
   
   START {$id} =>
      {foreach $nesting as $n}
         {$n},
      {/foreach}
{/function}


{function nestclose}
   END
{/function}


{nest}
   {nest id="test"}
      {nest id="test2"}
      {/nest}
   {/nest}
{/nest}


This is the result:
Code:
START root => root,
   START test => root,test,
      START test2 =>root,test2,
      END
   END
END



The result I want to have must be like this:
Code:
START root => root,
   START test => root,test,
      START test2 =>root,test,test2,
      END
   END
END


How can I achieve this? I hope somebody can help me.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon May 18, 2015 1:51 pm    Post subject: Reply with quote

If you need to define your nested structure by code like
Code:
{nest}
   {nest id="test"}
      {nest id="test2"}
      {/nest}
   {/nest}
{/nest}


Do not use template functions. You should create a block plugin.
See http://www.smarty.net/docs/en/plugins.block.functions.tpl

But why you can't assign the ID's in an array like
Code:
{$ids = ['rrot' => ['test' => ['test']]]}

and use some code similar to example 7.43 ?
See http://www.smarty.net/docs/en/language.function.function.tpl
Back to top
View user's profile Send private message
rickyheijnen
Smarty n00b


Joined: 18 May 2015
Posts: 2

PostPosted: Mon May 18, 2015 2:02 pm    Post subject: Reply with quote

Well... I dont have access to the PHP code, so I have to solve it with template functions. There is no other option Sad

The example I used in my post is simplefied to get my problem clear. Finally I want to use this:

Code:
{tabset id="maintab"}
   {tab id="first" label="First"}Here some tab content{/tab}
   {tab id="second" label="Second"}
      {tabset id="nestedtab"}
         {tab id="nestedfirst" label="Nested first"}Here some nested tab content{/tab}
         {tab id="nestedsecond" label="Nested second"}Here some more nested <b>tab content</b>{/tab}
      {/tabset}
{/tabset}


Which results in something like:
Code:
<div id="maintab" class="jqueryui-tabs">
   <div id="first">Here some tab content</div>
   <div id="second">

      <div id="nestedtab" class="jquery-tabs">
         <div id="nestedfirst">Here some nested tab content</div>
         <div id="nestedsecond">Here some more nested <b>tab content</b></div>
         
         <ul>
            <li rel="nestedfirst">Nested first</li>
            <li rel="nestedsecond">Nested second</li>
         </ul>
      </div>

   </div>
         
   <ul>
      <li rel="first">First</li>
      <li rel="second">Second</li>
   </ul>

</div>
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 -> General 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