|
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 |
rickyheijnen Smarty n00b
Joined: 18 May 2015 Posts: 2
|
Posted: Mon May 18, 2015 11:32 am Post subject: Use global variables in a nested function |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
rickyheijnen Smarty n00b
Joined: 18 May 2015 Posts: 2
|
Posted: Mon May 18, 2015 2:02 pm Post subject: |
|
|
Well... I dont have access to the PHP code, so I have to solve it with template functions. There is no other option
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 |
|
|
|
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
|